当前位置: 首页>>代码示例>>C#>>正文


C# DBConnection.RollbackTransaction方法代码示例

本文整理汇总了C#中DBConnection.RollbackTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnection.RollbackTransaction方法的具体用法?C# DBConnection.RollbackTransaction怎么用?C# DBConnection.RollbackTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBConnection的用法示例。


在下文中一共展示了DBConnection.RollbackTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: cleanUpDatabaseConnection

        private void cleanUpDatabaseConnection( DBConnection connection )
        {
            // Keep the connection initialized during cleanup to accommodate commit-time validation methods.
            try {
                try {
                    if( !DataAccessStatics.DatabaseShouldHaveAutomaticTransactions( connection.DatabaseInfo ) )
                        return;

                    try {
                        if( !transactionMarkedForRollback )
                            connection.CommitTransaction();
                    }
                    catch {
                        // Modifying this boolean here means that the order in which connections are cleaned up matters. Not modifying it here means
                        // possibly committing things to secondary databases that shouldn't be committed. We've decided that the primary connection
                        // is the most likely to have these errors, and is cleaned up first, so modifying this boolean here will yield the best results
                        // until we implement a true distributed transaction model with two-phase commit.
                        transactionMarkedForRollback = true;

                        throw;
                    }
                    finally {
                        if( transactionMarkedForRollback )
                            connection.RollbackTransaction();
                    }
                }
                finally {
                    connection.Close();
                }
            }
            finally {
                if( connection.DatabaseInfo.SecondaryDatabaseName.Any() )
                    secondaryDatabasesWithInitializedConnections.Remove( connection.DatabaseInfo.SecondaryDatabaseName );
                else
                    primaryDatabaseConnectionInitialized = false;
            }
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:37,代码来源:AppRequestState.cs


注:本文中的DBConnection.RollbackTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。