问题描述
TransactionOptions TransOpt = new TransactionOptions();
TransOpt.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
TransOpt.Timeout = new TimeSpan(0,2,0);
使用(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,TransOpt))
{
MySqlConnection conn = null;
conn = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings [_ ConnectionString]。ConnectionString);
conn.Open();
MySqlCommand objCmd;
objCmd = new MySql.Data.MySqlClient.MySqlCommand(query1,conn);
objCmd.ExecuteNonQuery();
MySqlConnection conn2 = null;
conn2 = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings [dbUpload_ConnectionString ] .ConnectionString);
conn2.Open(); ///错误行
MySqlCommand objCmd2;
objCmd2 = new MySql.Data.MySqlClient.MySqlCommand(query2,conn2);
objCmd2.ExecuteNonQuery();
TransactionOptions TransOpt = new TransactionOptions();
TransOpt.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
TransOpt.Timeout = new TimeSpan(0, 2, 0);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TransOpt))
{
MySqlConnection conn = null;
conn = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings["_ConnectionString"].ConnectionString);
conn.Open();
MySqlCommand objCmd;
objCmd = new MySql.Data.MySqlClient.MySqlCommand(query1, conn);
objCmd.ExecuteNonQuery();
MySqlConnection conn2 = null;
conn2 = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings["dbUpload_ConnectionString"].ConnectionString);
conn2.Open();///error line
MySqlCommand objCmd2;
objCmd2 = new MySql.Data.MySqlClient.MySqlCommand(query2, conn2);
objCmd2.ExecuteNonQuery();
conn.Close();
conn2.Close();
scope.Complete();
}
<pre lang="sql">When I run this, I get the error:
Multiple simultaneous connections or connections with different connection strings inside the same transaction are not currently supported
推荐答案
这篇关于如何将TransactionScope与MySql和多个数据库服务器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!