dotnet トランザクションが閉じられているかどうかを確認するにはどうすればよいですか?
3956 次
3 に答える
3
あなたのタイトルは 1 つのことを尋ね、あなたの質問は別のことを尋ねます。だから、私はあなたのタイトルで行きます。
トランザクションがロールバックされているか、ロールバックのみに設定されているかを知りたい場合は、確認できます
transaction.WasRolledBack // true if transaction is rolled back
これはITransactiontransaction
のインスタンスです
編集(コメントに基づく):
var isRolledBack = false;
using (var connection = new SqlConnection())
{
using (var transaction = connection.BeginTransaction())
{
try
{
// do your stuff here with transaction
}
catch (Exception ex)
{
transaction.Rollback();
isRolledBack = true;
throw;
}
}
}
これで、フラグをチェックしてisRolledBack
、トランザクションがロールバックされたかどうかを確認できます
于 2010-12-16T00:25:00.813 に答える
1
using(TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)){
try{
//Do something;
scope.Complete(); //denotes the transaction completed successful.
}
catch(TransactionAbortedException ex)
{
//scope.Complete(); is never called, the transaction rolls back automatically.
}
catch(ApplicationException ex)
{
}
}
于 2010-12-16T00:32:56.263 に答える
0
SQLサーバーを使用している場合は、使用できますDBCC OPENTRAN
于 2010-12-16T00:16:40.710 に答える