Skip to content

Instantly share code, notes, and snippets.

@kyonmm
Created October 14, 2014 09:28
Show Gist options
  • Save kyonmm/51de5c01e28aee409a50 to your computer and use it in GitHub Desktop.
Save kyonmm/51de5c01e28aee409a50 to your computer and use it in GitHub Desktop.
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