本文介绍了如何将TransactionScope与MySql和多个数据库服务器一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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和多个数据库服务器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:42