相关疑难解决方法(0)

"操作对事务状态无效"错误和事务范围

当我尝试调用包含SELECT语句的存储过程时,我收到以下错误:

该操作对交易状态无效

这是我的电话结构:

public void MyAddUpdateMethod()
{

    using (TransactionScope Scope = new TransactionScope(TransactionScopeOption.RequiresNew))
    {
        using(SQLServer Sql = new SQLServer(this.m_connstring))
        {
            //do my first add update statement

            //do my call to the select statement sp
            bool DoesRecordExist = this.SelectStatementCall(id)
        }
    }
}

public bool SelectStatementCall(System.Guid id)
{
    using(SQLServer Sql = new SQLServer(this.m_connstring)) //breaks on this line
    {
        //create parameters
        //
    }
}
Run Code Online (Sandbox Code Playgroud)

我在问题中创建了另一个与同一数据库的连接的问题吗?

.net c# sql-server transactions transactionscope

59
推荐指数
6
解决办法
9万
查看次数

TransactionScope TransactionAborted Exception - 事务未回滚.应该是吗?

(SQL SERVER 2008)如果在TransactionScope(.Complete())中发生事务超时错误,您是否希望回滚事务?

更新:
错误实际上是在结束大括号(即.Dispose())中抛出,而不是.Complete().完整错误是:

The transaction has aborted. System.Transactions.TransactionAbortedException TransactionAbortedException System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.TimeoutException: Transaction Timeout
   --- End of inner exception stack trace ---
   at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()
Run Code Online (Sandbox Code Playgroud)

据我所知,事务没有回滚,表格保持锁定,直到我对SPID/session_id发出了KILL.

我使用DBCC OPENTRAN获取最早的事务,然后杀死它.我已经尝试了KILL WITH STATUS但是收到一条消息,说明没有任何状态可用,因为没有回滚.sys.dm_exec_sessions中SPID/session_id的状态为"正在休眠".代码段:

try
{            
    using (var transaction = new TransactionScope())
    {
        LOTS OF WORK CARRIED OUT WITH LINQ ENTITIES/SubmitChanges() etc.
        transaction.Complete();  //Transaction timeout
    }
    return result;
}
catch (Exception ex)
{
    logger.ErrorException(ex.Message, ex);
    result.Fail(ex.Message); …
Run Code Online (Sandbox Code Playgroud)

c# sql-server transactionscope

16
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×2

sql-server ×2

transactionscope ×2

.net ×1

transactions ×1