TranscationScope用法示例
//标记是否已执行接口库中的操作
bool isYiZhiXingInterface = false;
using (TransactionScope transScope = new TransactionScope())
{
    DataBase dbLocal = new DataBase(_connectionString);
    DataBase dbInterface = new DataBase(_connectionStringInterface);
    try
    {
        dbLocal.BeginTrans();
        dbInterface.BeginTrans();
        dbLocal.RunSqlNonQuery_Trans(strSql);
        dbInterface.RunSqlNonQuery_Trans(strSqlInterface);
        isYiZhiXingInterface = true;
    }
    catch(System.Data.SqlClient.SqlException ex)
    {
        dbLocal.RollBack();
        if (isYiZhiXingInterface)
            dbInterface.RollBack();
        dbLocal.Dispose();
        dbInterface.Dispose();
        throw ex;
    }
    dbLocal.Commit();
    dbInterface.Commit();
    transScope.Complete();
    dbLocal.Dispose();
    dbInterface.Dispose();
    transScope.Dispose();
}
posted on 2009-03-19 13:45  雨季  阅读(462)  评论(0编辑  收藏  举报