MySQL的交易asp.net? [英] mysql transactions in asp.net?

查看:87
本文介绍了MySQL的交易asp.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们可以让我知道在asp.net处理事务的方式?

Can you guys let me know the way of handling transactions in asp.net?

即。我有具有作为一个整体来执行几个查询(在不同的功能present和在各种情况下的称呼)。所以,我应该怎么做呢?

i.e. I have a few queries (Present in different functions and called under various situations) that have to be executed as a whole. So, how should I go about it?

不知道的语法和.NET编写的语句的方法/实践(提交,回滚等)的

Not sure of the syntax and the method/practice for writing the statements in .net (commit, rollback etc).

请让我知道。此外,PLZ点我的一些好文章,如果可能的。谢谢!

Kindly let me know. Also, plz point me to some good articles if possible. Thanks!!!

推荐答案

我建议使用的的TransactionScope ,因为你可以使用它没有什么母校DB所使用。你甚至可以用它做分布式事务(在同一事务中对多个数据库的操作)。

I recommend using TransactionScope, because you can use it no mater what DB you are using. You can even do distributed transactions (operations against multiple databases within the same transaction) with it.

您可以参考链接为code的例子,但在一般情况下,你这样做:

You can refer to a link for a code example, but in general, you do this:

try
{
    using (TransactionScope scope = new TransactionScope())
    {
        using (MySqlConnection connection1 = new MySqlConnection (connectionString))
        {
            // Opening the connection automatically enlists it in the 
            // TransactionScope as a lightweight transaction.
            connection1.Open();

            // create the DB commands and perform the DB operations
            .
            .
            .

            // The Complete method commits the transaction. If an exception has been thrown,
            // Complete is not called and the transaction is rolled back.
            scope.Complete();    
        }
    }
}
catch (Exception e)
{
    // something went wrong, handle the exception accordingly. Note
    // that since we did not call TransactionScope.Complete, nothing
    // gets committed to the DB.
}

这篇关于MySQL的交易asp.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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