K
ken yup
Guest
there is a distributed transaction, i have configured the MSDTC & DTCping is successful,but it works not fine,it always stuck in second connection open,i cant figure it out why,i tried to change the ioslation level ,but it doesnt works,i just cant figure it out,plz help,my enviroment is a WIN2003 +SQL 2005 192.168.0.25 with 2 database db01 db02, & a Win2003+SQL 2000 192.168.0.20 db3
string[] connstr= new string[3];
connstr[0] = "server =192.168.0.25;database=db01;uid=sa;pwd=";
connstr[1] = "server =192.168.0.25;database=db02;uid=sa;pwd=";
connstr[2] = "server =192.168.0.20;database=db03;uid=sa;pwd=";
try
{
using (TransactionScope scope = TransactionScopeBuilder.CreateReadCommitted())
{
using (SqlConnection connection1 = new SqlConnection(connstr[0]))
{
try
{
connection1.Open();
// if (insertthegjd(connection1, 1, gjdwillupload, gjdmaindc) < 0) // this is i comment the codes because i doubt if they made the connection stoke,but when i comment them, the connection open is still stoke in connection2.open()
// return 10;
connection1.Close(); // this is i though if the connection1 is close,so i close it!
}
catch (Exception ex)
{
throw ex;
}
}
using (SqlConnection connection2 = new SqlConnection(connstr[1]))
{
try
{
connection2.Open();// the program is stuck in here,i have tried many ways,but they are not work
// if (insertthegjd(connection2, 2, gjdwillupload, gjdmaindc) < 0)
// return 10;
connection2.Close();
}
catch (Exception ex)
{
throw ex;
}
}
using (SqlConnection connection3 = new SqlConnection(connstr[2]))
{
try
{
connection3.Open();
// if (insertthegjd(connection3, 3, gjdwillupload, gjdmaindc) < 0)
// return 10;
connection3.Close();
}
catch (Exception ex)
{
throw ex;
}
}
// 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)
{
throw ex;
}
catch (ApplicationException ex)
{
throw ex;
}
//the following is i search in Stackoverflow,to change the isolation level
public static class TransactionScopeBuilder
{
/// <summary>
/// Creates a transactionscope with ReadCommitted Isolation, the same level as sql server
/// </summary>
/// <returns>A transaction scope</returns>
public static TransactionScope CreateReadCommitted()
{
var options = new TransactionOptions
{
IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
Timeout = new TimeSpan(0, 3, 0)
};
return new TransactionScope(TransactionScopeOption.Required, options);
}
}
many thanks
Continue reading...
string[] connstr= new string[3];
connstr[0] = "server =192.168.0.25;database=db01;uid=sa;pwd=";
connstr[1] = "server =192.168.0.25;database=db02;uid=sa;pwd=";
connstr[2] = "server =192.168.0.20;database=db03;uid=sa;pwd=";
try
{
using (TransactionScope scope = TransactionScopeBuilder.CreateReadCommitted())
{
using (SqlConnection connection1 = new SqlConnection(connstr[0]))
{
try
{
connection1.Open();
// if (insertthegjd(connection1, 1, gjdwillupload, gjdmaindc) < 0) // this is i comment the codes because i doubt if they made the connection stoke,but when i comment them, the connection open is still stoke in connection2.open()
// return 10;
connection1.Close(); // this is i though if the connection1 is close,so i close it!
}
catch (Exception ex)
{
throw ex;
}
}
using (SqlConnection connection2 = new SqlConnection(connstr[1]))
{
try
{
connection2.Open();// the program is stuck in here,i have tried many ways,but they are not work
// if (insertthegjd(connection2, 2, gjdwillupload, gjdmaindc) < 0)
// return 10;
connection2.Close();
}
catch (Exception ex)
{
throw ex;
}
}
using (SqlConnection connection3 = new SqlConnection(connstr[2]))
{
try
{
connection3.Open();
// if (insertthegjd(connection3, 3, gjdwillupload, gjdmaindc) < 0)
// return 10;
connection3.Close();
}
catch (Exception ex)
{
throw ex;
}
}
// 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)
{
throw ex;
}
catch (ApplicationException ex)
{
throw ex;
}
//the following is i search in Stackoverflow,to change the isolation level
public static class TransactionScopeBuilder
{
/// <summary>
/// Creates a transactionscope with ReadCommitted Isolation, the same level as sql server
/// </summary>
/// <returns>A transaction scope</returns>
public static TransactionScope CreateReadCommitted()
{
var options = new TransactionOptions
{
IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
Timeout = new TimeSpan(0, 3, 0)
};
return new TransactionScope(TransactionScopeOption.Required, options);
}
}
many thanks
Continue reading...