当我尝试调用包含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
//
}
}
在事务中创建另一个到同一数据库的连接是否会出问题?
await
会导致线程切换,而TransactionScope
与此不兼容。 - undefinedTransactionScopeAsyncFlowOption.Enabled
传递给TransactionScope
的构造函数时才能实现。 - undefined