2014-04-14 107 views
2

如何我可以在我的代碼中設置這個選項FbTransaction設置選項FbTransaction

write 
nowait 
rec_version 
read_committed 

執行插入/更新SQL語句:

FbConnectionStringBuilder fbConnStr = new FbConnectionStringBuilder(); 

using (FbConnection fbConn = new FbConnection(fbConnStr)) 
{ 
    fbConn.Open(); 
    using (FbTransaction fbTran = fbConn.BeginTransaction()) 
    { 
     using (FbCommand fbCmd = new FbCommand("insert into TEST values (1)", fbConn, fbTran) 
     { 
     fbCmd.CommandType = CommandType.Text; 
     fbCmd.ExecuteNonQuery(); 
     fbCmd.Transaction.Commit(); 
     } 
    } 
    fbConn.Close(); 
} 

回答

2

你可以使用FbTransactionOptions

FbTransaction transaction = Connection.BeginTransaction(
    FbTransactionOptions.ReadCommitted | 
    FbTransactionOptions.Write| 
    FbTransactionOptions.RecVersion| 
    FbTransactionOptions.NoWait | 
    ); 

請看IsolationLevel

  • IsolationLevel.ReadUncommitted
  • IsolationLevel.ReadCommitted
  • IsolationLevel.RepeatableRead
  • IsolationLevel.Serializable

你可以這樣做:

FbTransaction transaction = Connection.BeginTransaction(IsolationLevel.Serializable);