2
데이터베이스 집약적 인 응용 프로그램의 핵심 요소 중 하나는 트랜잭션을 가능한 짧게 유지하는 것입니다.ADO.NET으로 작성된 db 트랜잭션은 실제로 언제 시작됩니까?
오늘은이 거래 실제로 시작할 것이다 때 궁금 : 단계 (1)에서
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
sqlConnection.Open();
/*(1)*/ SqlTransaction sqlTransaction = sqlConnection.BeginTransaction(IsolationLevel.ReadUncommitted);
//Perform some stuff
//...
/*(2)*/ using (SqlCommand command = new SqlCommand(sqlQuery, sqlConnection, sqlTransaction))
{
//Some other stuff
//...
try
{
/*(3)*/sqlCommand.ExecuteNonQuery();
//More irrelevant code
//...
sqlCommand.CommandText = otherQuery;
sqlCommand.ExecuteNonQuery();
sqlTransaction.Commit();
}
catch(Exception)
{
sqlTransaction.Rollback();
throw;
}
}
}
을, (2) 또는 (3)? 이상적으로 3 단계에 있어야합니다.
좋은 질문입니다, 잊지 마세요 sqlTransaction.Rollback(); 실패 할 수도 ... –