【问题标题】:Transactions not working for SubSonic under Oracle?事务不适用于 Oracle 下的 SubSonic?
【发布时间】:2011-02-01 08:42:27
【问题描述】:

以下代码示例在 SQL Server 2005 下完美运行:

using (TransactionScope ts = new TransactionScope()) {
            using (SharedDbConnectionScope scope = new SharedDbConnectionScope()) {
                MyTable t = new MyTable();
                t.Name = "Test";
                t.Comments = "Comments 123";
                t.Save();
                ts.Complete();
            }
        }

但在 Oracle 10g 下,它会抛出“ORA-02089:从属会话中不允许提交”错误。如果我只执行 SharedDbConnectionScope 块内的代码,那么一切正常,但显然我将无法在事务下执行操作,从而冒着数据损坏的风险。

这只是我的实际应用程序的一小部分示例。我不确定是什么导致了这种行为;有没有人愿意解释一下这个问题?


这是配置:

<configSections> <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" requirePermission="false"/> </configSections> <connectionStrings> <add name="OracleConnection" connectionString="Data Source=XE;User Id=test;Password=test;"/> </connectionStrings> <SubSonicService defaultProvider="OracleProvider"> <providers> <clear/> <add name="OracleProvider" type="SubSonic.OracleDataProvider, SubSonic" connectionStringName="OracleConnection" generatedNamespace="OracleTest" /> </providers> </SubSonicService> 

【问题讨论】:

    标签: oracle subsonic transactions commit


    【解决方案1】:

    Lookingup 该特定错误消息表明某些东西可能正在尝试显式或隐式 COMMIT。

    如果您查看OracleDataProvider.cs,在 GetInsertSql(Query qry) 中会发出显式 COMMIT:

        if (retrieveID)
            insertSQL.AppendFormat("  RETURNING {0} INTO :lllhhhmmm; COMMIT; END; ", qry.Schema.PrimaryKey.ColumnName);
    

    COMMIT 在同一个文件的 ExecuteScalar() 中也被调用。当您更新记录而不是插入记录时,您是否仍然看到问题?

    【讨论】:

    • 我还是发现了一个问题,只是更新时出现了不同的问题。我收到 InvalidOperationException 消息:“无效操作。连接已关闭。”所用代码的唯一区别是添加了这行代码: MyTable t = new MyTable(8);传递表中有效记录的 Id,而不是使用无参数构造函数。
    【解决方案2】:

    尝试删除

    using (TransactionScope ts = new TransactionScope())
    

    并且只使用 SharedDbConnectionScope,像这样:

            SharedDbConnectionScope scope = new SharedDbConnectionScope();
            using (scope) {
                MyTable t = new MyTable();
                t.Name = "Test";
                t.Comments = "Comments 123";
                t.Save();
                scope.commit();
            }
    

    【讨论】:

      猜你喜欢
      • 2010-10-12
      • 2012-12-26
      • 1970-01-01
      • 2014-11-05
      • 2015-05-17
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多