Created
October 14, 2014 09:28
-
-
Save kyonmm/51de5c01e28aee409a50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (SqlTransaction transaction = connection.BeginTransaction()) | |
{ | |
try | |
{ | |
// 処理 | |
transaction.Commit(); | |
} | |
catch | |
{ | |
if(MyRollback(transaction) == false){ | |
throw; | |
} | |
} | |
} | |
boolean MyRollback(transaction){ | |
try{ | |
transaction.Rollback(); | |
return true; // 正常にロールバック | |
} | |
catch(InvalidOperationException e){ | |
return true; // 反映済みトランザクションでロールバックしたときに発生する例外なので、成功とみなす | |
} | |
catch(Exception){ | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment