使用常用方法

时间:2011-07-23 10:26:49

标签: sql asp.net

  

我正在使用以下方法进行所有数据插入和更新   我的application.i中的进程只需要传递sql quires数组   方法。使用一种常用方法有任何缺点   它会导致应用程序性能下降

 public int ExecuteCommand(string[] sqls)
        {
            numberOfRecordsAffected = 0;

            IngresConnection ingresConnection = new IngresConnection(ConnStr);
            IngresTransaction ingresTransaction = null;
            try
            {
                ingresConnection.Open();

                ingresTransaction = ingresConnection.BeginTransaction();

                foreach (string sql in sqls)
                {
                    IngresCommand ingresCommand = new IngresCommand(sql, ingresConnection, ingresTransaction);
                    ingresCommand.CommandTimeout = 0;
                    numberOfRecordsAffected += ingresCommand.ExecuteNonQuery();
                }

                ingresTransaction.Commit();

            }
            catch
            {
                if (ingresTransaction != null)
                    ingresTransaction.Rollback();
                ingresConnection.Close();
                throw;
            }
            finally
            {
                if (ingresConnection != null)
                    ingresConnection.Close();
            }

            return numberOfRecordsAffected;
        }

1 个答案:

答案 0 :(得分:1)

有关动态sql的信息,请参阅此opinionated article。你特别询问了确实受到很大伤害的性能,因为数据库无法缓存您的查询,并且每个查询都需要进行解析。真正的担忧应该是安全性。在一个点或另一个点上做错了/不完全是如此容易,而且测试它是否已经被搞砸了甚至更难。