大家好,又见面了,我是你们的朋友全栈君。
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();
}
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
解决方案
Please close the first connection before opening the next one.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/161951.html原文链接:https://javaforall.cn