2010-01-28 68 views
1

我正在嘗試使用IfxCommand執行一個簡單的選擇查詢。我想將隔離設置爲髒讀,但我只找到了在IfxTransaction環境中設置隔離級別的示例。我不需要交易,因爲我只是發佈一條select語句。以下是我目前的代碼,這是最好的方法嗎?此外,如果您知道隔離級別保持多久以設置爲髒讀,我想知道。設置隔離w/o ifxtransaction?

DataSet ds = new DataSet(); 
     IfxConnection connection = new IfxConnection(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString); 
     IfxCommand command = new IfxCommand(); 

     try 
     { 
      connection.Open();     
      command.Connection = connection; 
      command.CommandText = "SET ISOLATION TO DIRTY READ"; 
      command.ExecuteNonQuery(); 

      command.CommandText = BuildCommandString(); 

      IfxDataAdapter idap = new IfxDataAdapter(command.CommandText, connection); 
      idap.Fill(ds); 
     } 
+0

這有幫助嗎?我不熟悉Informix。 http://stackoverflow.com/questions/2111507/informix-net-provider-and-transactionscope-not-rolling-back – Amy 2010-01-28 18:04:06

回答

0

using (var noTransaction = new TransactionScope(TransactionScopeOption.Suppress)) { 
    // Use your connection here 
} 

工作?不確定Informix是否將自己列入環境交易?或者 - 如果你想在嵌套事務明確設置的IsolationLevel:

var txOptions = new TransactionOptions(); 
txOptions.IsolationLevel = IsolationLevel.ReadUncommitted; 
txOptions.Timeout.TotalSeconds * 2)); 
using (var noTransaction = new TransactionScope(TransactionScopeOption.RequiresNew, txOptions)) { 
    // Use your connection here 
} 

編輯:剛纔讀的refered到Informix和TransactionScopes評論。您必須更改代碼以反映那裏的解決方案。