将选项设置为FbTransaction

时间:2014-04-14 11:32:04

标签: c# .net visual-studio transactions firebird

如何将此选项设置为FbTransaction

write
nowait
rec_version
read_committed

在我的代码中执行insert / update 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();
}

1 个答案:

答案 0 :(得分:3)

您可以使用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 );