3

MYSQL 是否支持 TransactionScope 而无需将 MySqlConnection 对象作为参数传递?或者它只适用于 MS SQL 2008 及更高版本?

例如:

public void Method()
{
    using (var scope = new System.Transactions.TransactionScope())
    {
        Delete();
        Insert();
        Update();

        scope.Complete();
    }
}

public void Update()
{
     using(MySqlConnection conn = new MySqlConnection())
     {
         // Update something in the Database
     }
}

public void Insert()
{
     using(MySqlConnection conn = new MySqlConnection())
     {
         // Insert something in the Database
     }
}

public void Delete()
{
     using(MySqlConnection conn = new MySqlConnection())
     {
         // Delete something from Database
     }
}

或者我应该使用 MySqlConnection conn 对象作为参数吗?

public void Method()
{
    using (var scope = new System.Transactions.TransactionScope())
    {
        using(MySqlConnection conn = new MySqlConnection())
        {
            Delete(conn);
            Insert(conn);
            Update(conn);
        }

        scope.Complete();
    }
}

public void Update(MysqlConnection conn)
{
    // Update something in the Database
}

public void Insert(MysqlConnection conn)
{
    // Insert something in the Database
}

public void Delete(MysqlConnection conn)
{
    // Delete something from Database
}
4

1 回答 1

0

您不能MySqlConnection在单个对象中创建多个对象TransactionScope错误 50773

一个解决方案是升级到支持 TransactionScopehttps://github.com/mysql-net/MySqlConnector

于 2018-01-28T02:45:46.847 回答