【问题标题】:Set isolation w/o an ifxtransaction?设置没有 ifxtransaction 的隔离?
【发布时间】:2011-01-10 12:46:48
【问题描述】:

我正在尝试使用 IfxCommand 执行一个简单的选择查询。我想将隔离设置为脏读,但我只找到了在 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);
        }

【问题讨论】:

标签: c# isolation-level


【解决方案1】:

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

工作?不确定 Informix 是否参与环境事务?或者 - 如果您想在嵌套事务中显式设置隔离级别:

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

编辑:只需阅读有关 Informix 和 TransactionScopes 的评论。您必须更改代码以反映那里的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    相关资源
    最近更新 更多