• 使用TransactionScope时出现“与基础事务管理器的通信失败”的错误


    在使用TransactionScope时 出错。(如果不使用事务则不出错)
    以下是使用TransactionScope 这个的测试代码一周了,问题仍然没有解决,希望大家指教。
    应用程序服务器与数据库服务器分别在不同的机器上。
    string connectionString = @"Data Source=server\sql2005;Initial Catalog=DataTest;User ID=sa;Password=123456;enlist=true";
               using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    SqlParameter[] parameters =
                    {
                        new SqlParameter("@UserName", SqlDbType.NVarChar,50),
                        new SqlParameter("@Fund", SqlDbType.Money)
                    };
                    parameters[0].Value = "admin";
                    parameters[1].Value = 12.0;
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = conn;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "User_UpdateFund";
                        cmd.Parameters.AddRange(parameters);
                        conn.Open();
                        cmd.ExecuteNonQuery();                                       
                    }
                    using (SqlConnection conn1 = new SqlConnection(connectionString))
                    {
                        SqlParameter[] parameters1 =
                                {
                                    new SqlParameter("@From", SqlDbType.NVarChar,50),
                                    new SqlParameter("@To",SqlDbType.NVarChar,50),
                                    new SqlParameter("@Fund", SqlDbType.Money)
                                };
                        parameters1[0].Value = "admin";
                        parameters1[1].Value = "agent";
                        parameters1[2].Value = 12.0;
                        SqlCommand cmd1 = new SqlCommand();
                        cmd1.Connection = conn1;
                        cmd1.CommandType = CommandType.StoredProcedure;
                        cmd1.CommandText = "FundLog_Add";
                        cmd1.Parameters.AddRange(parameters1);
                        conn1.Open();
                        cmd1.ExecuteNonQuery();
                    }
                    ts.Complete();
  • 相关阅读:
    360手机青春版原装充电器
    然并卵却很拉风!360超级充电器评测_天极网
    39元超值!360超级充电器拆解与评测
    99元紫米10000mAh移动电源开箱拆解
    自己DIY PCB电路板制作(简单方便快捷)
    Easy EDA:在线创客软件服务是未来的趋势 | 雷锋网
    EasyEDA
    我的那些年(9)~我来团队了,Mvc兴起了
    我的那些年(8)~去朋友公司做网站开发
    我的那些年(7)~第一份互联网工作
  • 原文地址:https://www.cnblogs.com/rosanshao/p/843685.html
Copyright © 2020-2023  润新知