2011-07-23 30 views
0

我使用的所有数据插入和更新在我application.i 过程只需要那里穿过SQL奎雷斯的阵列 的method.are使用一种常用的方法中的任何缺点,下面的方法.does 造成任何性能下降的应用使用常见的方法

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

看到这个opinionated article有关动态SQL。您特别询问性能确实受到很大影响,因为您的查询不能被数据库缓存,并且每个数据都需要被解析。真正的担心应该是关于安全性。在一个点或另一个点上做错误/不完整是很容易的,而且测试它是否在某处出现混乱甚至更难。

相关问题