我在特定的SQL Server 2008客户安装上遇到问题。我编写了下面的代码来模拟在更复杂的系统中发生的问题。打开了两个连接(每个连接都有自己的事务),每个连接都修改一个表。修改后的表彼此无关。在开发平台和其他现有客户安装上,代码工作正常。仅在一个特定客户处,我们遇到嵌套事务中的第二次更新挂起的问题。我可以通过在提交嵌套事务后移动第一个更新来制定解决方法。
我假设在该特定安装中,db被配置为在启动事务时锁定整个db。但是使用DBCC useroptions
会在代码工作的系统和这个系统上产生非常相似的输出。
我如何识别这里的错误?
这是问题数据库(SQL Server 2008)的DBCC useroptions
输出和我的简化测试代码:
textsize 2147483647
language Deutsch
dateformat dmy
datefirst 1
lock_timeout -1
quoted_identifier SET
arithabort SET
ansi_null_dflt_on SET
ansi_warnings SET
ansi_padding SET
ansi_nulls SET
concat_null_yields_null SET
isolation level read committed
DbCommand command1 =null, command2 = null;
try
{
const string cs = "Provider=SQLOLEDB.1;...";
// open command and a transaction with default isolation level
command1 = DbAccessFactory.CreateInitialzedCommand("System.Data.OleDb", cs, true);
// select something
command1.CommandText = "select * from plannerOrderHeaders where ...";
DataSet ds = BusinessCasesHelper.Fill(command1, null, "plannerOrderHeaders");
// make some changes in the table
...
// update the table in DB
BusinessCasesHelper.Update(command1, ds, true);
// open command and a transaction with default isolation level on the same CS as command1
command2 = DbAccessFactory.CreateInitialzedCommand("System.Data.OleDb", cs, true);
// select something
command2.CommandText = "select * from mdOmOrders where ...";
ds = BusinessCasesHelper.Fill(command2, null, "mdOmOrders");
// make some changes
...
// update the db
BusinessCasesHelper.Update(command2, ds, true);
command2.Transaction.Commit();
cmd2Commited = true;
command1.Transaction.Commit();
}
catch (Exception e) {...}
答案 0 :(得分:0)
为什么使用“”Provider = SQLOLEDB.1“来访问MS SQL Server? 为什么你承诺而不是关闭和处置?
我只能猜测所提到的BusinessCasesHelper,DbAccessFactory等是如何实现的。
但是你的问题意味着你在同一个环境中(即在一个连接上)考虑你的代码段开放事务在另一个事务中,而我看到他们可能正在打开两个没有被处置的连接。