SQL

1.query all the store prodecure in the specified db.

select * from INFORMATION_SCHEMA.ROUTINES where ROUTINE_TYPE='PROCEDURE';

2.find the store procedure text.

select ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES where SPECIFIC_NAME='SOD2SP';

3.define transaction with try catch rollback

BEGIN TRY

UPDATE SOD2 SET ModifiedDate=GETDATE() where SalesOrderDetailID%5=0

END TRY

BEGIN CATCH

ROLLBACK TRANSACTION UPDATE5TRANS

END CATCH

 4.C# Dapper Transaction

using System;
using System.Data;
using Dapper;

namespace DBDll.Dll
{
    public class SQLTransactionLevelDemo
    {
        public static void TransShow()
        {
            using (IDbConnection conn = DBCommon.GetSqlConnection())
            {
                if(conn.State!=System.Data.ConnectionState.Open)
                {
                    conn.Open();
                }
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        string sql = "update SOD2 set ModifiedDate=GETUTCDATE() where SalesOrderDetailID%10=0;";
                        int updatedRows = conn.Execute(sql,new { }, trans,commandType:System.Data.CommandType.Text);
                        trans.Commit();                        
                    }
                    catch(Exception ex)
                    {
                        trans.Rollback();
                    }                    
                }
            }
        }
    }
}
原文地址:https://www.cnblogs.com/Fred1987/p/11433143.html