在使用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();
posted on 2007-08-05 13:40  rosanshao  阅读(1434)  评论(3编辑  收藏  举报