本文介绍了"操作是无效的事务和QUOT的状态;错误和交易范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误,当我尝试调用存储过程,它包含一个SELECT语句:
I am getting the following error when I try to call a stored procedure that contains a SELECT Statement:
的操作是无效的事务的状态
下面是我的电话的结构:
Here is the structure of my calls:
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 DoesRecordExist(System.Guid id)
{
using(SQLServer Sql = new SQLServer(this.m_connstring)) //breaks on this line
{
//create parameters
//
}
}
是我创造的事务中的另一个连接到同一数据库的问题?
Is the problem with me creating another connection to the same database within the transaction?
推荐答案
之后做一些研究,看来我不能有两个连接打开到同一数据库与TransactionScope的块。我需要改变我的code看起来是这样的:
After doing some research, it seems I cannot have two connections opened to the same database with the TransactionScope block. I needed to modify my code to look like this:
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
}
//removed the method call from the first sql server using statement
bool DoesRecordExist = this.SelectStatementCall(id)
}
}
public bool SelectStatementCall(System.Guid id)
{
using(SQLServer Sql = new SQLServer(this.m_connstring))
{
//create parameters
}
}
这篇关于"操作是无效的事务和QUOT的状态;错误和交易范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!