在MySQL中使用System.Transactions.TransactionScope [英] Using System.Transactions.TransactionScope with MySQL

查看:93
本文介绍了在MySQL中使用System.Transactions.TransactionScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我在使用System.Transactions.TransactionScope类时遇到问题。我当前的代码块似乎没有"回滚"我上一次数据库插入操作。这是一个模拟的异常。

顺便说一下,我使用MYSQL作为我的数据库。




using(TransactionScope scope = new TransactionScope())
{
try
{
MySqlConnection conn = new MySqlConnection(" server) = localhost; user id = root; password = raymond; database = ccp; minimum pool size = 0;" +
" maximum pool size = 1000; connection lifetime = 3600; procedure cache size = 1000"); < br> MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText =" AddCategory" ;;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(" pName",name) ;
cmd.Parameters.Add(" pParentCategoryID",0);

MySqlParameter param = new MySqlParameter();
param.ParameterName = " pCategoryID";
param.Direction = ParameterDirection.Output;
param.Value = null;

cmd.Parameters.Add(param);
conn.Open(); < br> cmd.ExecuteNonQuery();

抛出新的异常(); //这里是模拟异常在此行之后,最新的数据库插入没有回滚。
}
catch(Exception ex)
{

}


解决方案

很抱歉这么晚才发布回复。您现在必须已收到解决方案。

无论如何,请检查您正在使用的MySql .Net Connector版本。如果人们在框架2.0中使用.NET 1.1的提供程序,人们通常会面临这个问题。

TransactionScope,infact System.Transaction名称空间已在.Net Framework 2.0及更高版本中提供。因此,您需要使用为.net framework 2.0发布的提供程序。

对于MySQL,请使用http://dev.mysql.com/downloads/connector/net/5.2.html 搜索结果的问候,结果,阿密特


Hello to all.

I'm having problems with use of the System.Transactions.TransactionScope class. My current code block doesn't seem to "rollback" my last DB Insert operation. This is a simulated Exception.

And by the way, im using MYSQL as my database.

using (TransactionScope scope = new TransactionScope())
{
    try
    {
        MySqlConnection conn = new MySqlConnection("server=localhost;user id=root;password=raymond;database=ccp;minimum pool size=0;" +
                         "maximum pool size=1000;connection lifetime=3600;procedure cache size=1000");
        MySqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = "AddCategory";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("pName", name);
        cmd.Parameters.Add("pParentCategoryID", 0);

        MySqlParameter param = new MySqlParameter();
        param.ParameterName = "pCategoryID";
        param.Direction = ParameterDirection.Output;
        param.Value = null;

        cmd.Parameters.Add(param);
        conn.Open();
        cmd.ExecuteNonQuery();

        throw new Exception(); // Simulated Exception here. After this line, the latest DB insert did not rollback.
    }
    catch (Exception ex)
    {

    }
}

解决方案

Hi, Sorry for posting the reply so late. You must have received the solutions by now.

Anyways, Please check the MySql .Net Connector version you are using. People generally face this issue with database provider if they are using a provider for .NET 1.1 in framework 2.0.

TransactionScope, infact System.Transaction namespace has been provided in .Net Framework 2.0 and above. So you need to use the provider released for .net framework 2.0.

For MySQL please use the version 5.1.7 and above from http://dev.mysql.com/downloads/connector/net/5.2.html

Regards,
Amit


这篇关于在MySQL中使用System.Transactions.TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆