zoukankan      html  css  js  c++  java
  • 跨数据库分布式事务的处理

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.EnterpriseServices;
    using System.Data.SqlClient;

    namespace myCOM
    {
        [Transaction(TransactionOption.Required)]
        public class MyComClass : ServicedComponent
        {
            public SqlConnection Conn;
            public SqlConnection Conn1;

            public void test(string updateStr)
            {
                try
                {
                    string connection = string.Format("server = pwdpc; database = Northwind; uid = sa; pwd = ******;");
                    SqlConnection Conn = new SqlConnection(connection);
                    Conn.Open();

                    string connection1 = string.Format("server = pwdpc; database = pubs; uid = sa; pwd = ******;");
                    SqlConnection Conn1 = new SqlConnection(connection1);
                    Conn1.Open();

                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = Conn;
                    cmd.CommandType = System.Data.CommandType.Text;
                    string sqlSentence = string.Format("update dbo.Customers set CompanyName = '{0}' where CustomerID = 'ALFKI'", updateStr);
                    cmd.CommandText = sqlSentence;
                    cmd.ExecuteNonQuery();

                    //出异常
                    //int i = 0;
                    //int j = 1 / i;

                    SqlCommand cmd1 = new SqlCommand();
                    cmd1.Connection = Conn1;
                    cmd1.CommandType = System.Data.CommandType.Text;
                    string sqlSentence1 = string.Format("update dbo.authors set au_fname = '{0}' where au_lname = 'White'", updateStr);
                    cmd1.CommandText = sqlSentence1;
                    cmd1.ExecuteNonQuery();

                    ContextUtil.SetComplete();
                    Conn.Close();
                    Conn1.Close();
                }
                catch (Exception ex)
                {
                    ContextUtil.SetAbort();
                    throw ex;
                }
                finally
                { }
            }
        }
    }

  • 相关阅读:
    Halcon学习(车牌识别)
    Keil新建STM32工程(LED灯)
    Keil新建STM32工程(LED灯)
    Keil STM32F4xx_DFP.1.0.8.pack下载链接
    android 如何单独编译 img及作用
    Linux绑定硬件IRQ到指定SOC的CPU核
    sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f)
    内核线程同步之completion
    kmalloc,vmalloc , malloc
    ARMv8 与 Linux的新手笔记(转载)
  • 原文地址:https://www.cnblogs.com/EddyPeng/p/1225851.html
Copyright © 2011-2022 走看看