我有一个TransactionScope()
块。它总是卡在插入语句上。它在Activity Monitor中显示为阻塞任务,因此它会阻塞SQL服务器,在超时后,我会收到以下错误:
该操作对事务状态无效。
发生了什么问题?
const TransactionScopeOption opt = new TransactionScopeOption();
TimeSpan span = new TimeSpan(0, 0, 1, 30);
try
{
using (TransactionScope scope01 = new TransactionScope(opt, span))
{
using (var sqlcon = new SqlConnection(sSqlCon))
{
//select,insert , update statements
}
}
}
catch (Exception ex)
{
}