相关疑难解决方法(0)

在SQL Server 2014中使用TransactionScope围绕存储过程与事务

我正在使用C#和ADO.Net TransactionScope来运行ASP.Net应用程序中的事务.此事务应该在多个表中保存一些数据,然后向订阅者发送电子邮件.

:这是一个有效的使用TransactionScope,当它包括到在SQL Server 2014年自己的事务存储过程的调用,或者我应该删除SQL事务语句,即begin tran,commit tran并且rollback tran从存储过程的语句被内这个叫TransactionScope

下面提到了此场景的C#代码以及存储过程的T-SQL代码.

C#代码使用TransactionScope:

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

                // SaveEmailData is a stored procedure that has a transaction within it
                SqlCommand command1 = new SqlCommand("SaveEmailData", connection1);
                command1.CommandType = CommandType.StoredProcedure;
                command1.ExecuteNonQuery();

            }

            //Send …
Run Code Online (Sandbox Code Playgroud)

c# sql-server ado.net stored-procedures transactionscope

13
推荐指数
1
解决办法
1万
查看次数