You use a local transaction to execute two SqlCommands, as shown here:

using (SqlConnection connection = new SqlConnection(connectionString))
SqlCommand command = connection.CreateCommand();
SqlTransaction transaction = connection.BeginTransaction("SampleTransaction");
command.CommandText = updateSQLCommandText;
command.CommandText = insertSQLCommandText;
catch (Exception ex)

When you test this code, you find that after adding the transaction code, the first command throws an exception. You must fix the problem and ensure transactional behavior.

What should you do?

 Posted by Rajkatie on 9/30/2012 | Category: ADO.NET Interview questions | Views: 1199 | Points: 40
Select from following answers:
  1. Set the Transaction property of SqlCommand to the transaction returned by BeginTransaction.
  2. Set an isolation level of ReadCommitted or higher explicitly when beginning the transaction.
  3. Begin the transaction before creating the command.
  4. All Above

Show Correct Answer

Source: MeasureUp.Com | | Alert Moderator 

Comments or Responses

Login to post response