已经设置了隔离级别比较低了,可是做事务时还是死锁
下面是在第二个连接的时候就卡住了,也就是说在 connection2.Open();的时候卡住,不知道为什么
我的代码就是做个分布式事物,环境已经设好(MSDTC已经设好,并且DTCPING 都PING过,没问题),不知道卫什么回死锁,我的是测试环境, gjdwillupload 是个返型 LIST<T>,代码是查MSDN和往上的资料写的,请帮帮我,非常感谢,我环境是 192.168.0.25 是 WIN2K3+ SQL 2005,192.168.0.20是 WIN 2003+ SQL 2000
string[] connstr= new string[3];
connstr[0] = "server =192.168.0.25;database=db1;uid=sa;pwd=";
connstr[1] = "server =192.168.0.25;database=db2;uid=sa;pwd=";
connstr[2] = "server =192.168.0.20;database=db3;uid=sa;pwd=";
TransactionOptions tpt = new TransactionOptions();
tpt.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
tpt.Timeout = new TimeSpan(0, 3, 0);
try
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, tpt))
{
using (SqlConnection connection1 = new SqlConnection(connstr[0]))
{
try
{
connection1.Open();
if (insertthegjd(connection1, 1, gjdwillupload, gjdmaindc)<0)// gjdwillupload 就是个 LIST<T>,gjdmaindc是个类
return 10;
using (SqlConnection connection2 = new SqlConnection(connstr[1]))
{
try
{
connection2.Open(); // 就在这卡住
if (insertthegjd(connection2, 2, gjdwillupload, gjdmaindc) < 0)
return 10;
using (SqlConnection connection3 = new SqlConnection(connstr[2]))
{
try
{
connection3.Open();
if (insertthegjd(connection3, 3, gjdwillupload, gjdmaindc) < 0)
return 10;
}
catch (Exception ex)
{
UploadthegjdFault upgjdf = new UploadthegjdFault();
upgjdf.Operation = "when insert the records";
upgjdf.ProblemType = "occur the exception";
string expmessag = ex.ToString();
if (expmessag.Length > 900)
expmessag = ex.ToString().Substring(0, 900);
logtheexp(ip, myusername, upgjdf.Operation + upgjdf.ProblemType + expmessag);
throw new FaultException<UploadthegjdFault>(upgjdf);
}
}
}
catch (Exception ex)
{
UploadthegjdFault upgjdf = new UploadthegjdFault();
upgjdf.Operation = "when insert the records";
upgjdf.ProblemType = "occur the exception ";
string expmessag = ex.ToString();
if (expmessag.Length > 900)
expmessag = ex.ToString().Substring(0, 900);
logtheexp(ip, myusername, upgjdf.Operation + upgjdf.ProblemType + expmessag);
throw new FaultException<UploadthegjdFault>(upgjdf);
}
}
}
catch (Exception ex)
{
UploadthegjdFault upgjdf = new UploadthegjdFault();
upgjdf.Operation = "when insert the records";
upgjdf.ProblemType = "insert exception happen";
string expmessag = ex.ToString();
if (expmessag.Length > 900)
expmessag = ex.ToString().Substring(0, 900);
logtheexp(ip, myusername, upgjdf.Operation + upgjdf.ProblemType + expmessag);
throw new FaultException<UploadthegjdFault>(upgjdf);
}
}
// The Complete method commits the transaction. If an exception has been thrown,
// Complete is not called and the transaction is rolled back.
scope.Complete();
return 1;
}
}
catch (TransactionAbortedException ex)
{
UploadthegjdFault upgjdf = new UploadthegjdFault();
upgjdf.Operation = "when the transaction is coming";
upgjdf.ProblemType = "insert exception";
string expmessag = ex.ToString();
if (expmessag.Length > 900)
expmessag = ex.ToString().Substring(0, 900);
logtheexp(ip, myusername, upgjdf.Operation + upgjdf.ProblemType + expmessag);
throw new FaultException<UploadthegjdFault>(upgjdf);
}
catch (ApplicationException ex)
{
UploadthegjdFault upgjdf = new UploadthegjdFault();
upgjdf.Operation = "when insert the records ";
upgjdf.ProblemType = "ocur exception";
string expmessag = ex.ToString();
if (expmessag.Length > 900)
expmessag = ex.ToString().Substring(0, 900);
logtheexp(ip, myusername, upgjdf.Operation + upgjdf.ProblemType + expmessag);
throw new FaultException<UploadthegjdFault>(upgjdf);
}