异常报错 帮吗分析一下原因 是否using
SqlCommand Command = null;
SqlTransaction Transaction = null;
try
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
Command = new SqlCommand();
Command.Connection = conn;
Command.CommandType = CommandType.Text;
Command.CommandText = sqlString;
conn.Open();
Transaction = conn.BeginTransaction();
Command.Transaction = Transaction;
Command.ExecuteNonQuery();
Transaction.Commit();
Command.Parameters.Clear();
}
}
catch (Exception ex)
{
Transaction.Rollback();
throw new Exception(string.Format("执行{0}语句时出现异常。", sqlString), ex);
}
如果执行上面的语句出现异常的话 Transaction.Rollback(); 按说应该回滚事物 但是到这里会出错。请问为什么?
难道是using (SqlConnection conn = new SqlConnection(ConnectionString))这句话的问题?