当我尝试调用包含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)
我在问题中创建了另一个与同一数据库的连接的问题吗?
(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)