本文整理汇总了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;
}
}