Which code segment should you insert at line 11?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You write the following code segment that executes two commands against the database within a transaction. (Line numbers are included for reference only.)
01 Using connection As New SqlConnection(cnnStr)
02 connection.Open()
03 Dim sqlTran As SqlTransaction = connection.BeginTransaction()
04 Dim command As SqlCommand = connection.CreateCommand()
05 command.Transaction = sqlTran
06 Try
07 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong size’)”
08 command.ExecuteNonQuery()
09 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong color’)”
10 command.ExecuteNonQuery()
11
12 End Using

You need to log error information if the transaction fails to commit or roll back.
Which code segment should you insert at line 11?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You write the following code segment that executes two commands against the database within a transaction. (Line numbers are included for reference only.)
01 Using connection As New SqlConnection(cnnStr)
02 connection.Open()
03 Dim sqlTran As SqlTransaction = connection.BeginTransaction()
04 Dim command As SqlCommand = connection.CreateCommand()
05 command.Transaction = sqlTran
06 Try
07 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong size’)”
08 command.ExecuteNonQuery()
09 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong color’)”
10 command.ExecuteNonQuery()
11
12 End Using

You need to log error information if the transaction fails to commit or roll back.
Which code segment should you insert at line 11?

A.
sqlTran.Commit() Catch ex As Exception sqlTran.Rollback() Trace.WriteLine(ex.Message) End Try

B.
sqlTran.Commit() Catch ex As Exception Trace.WriteLine(ex.Message) Try sqlTran.Rollback() Catch exRollback As Exception Trace.WriteLine(exRollback.Message) End Try
End Try

C.
Catch ex As Exception Trace.WriteLine(ex.Message) Try sqlTran.Rollback() Catch exRollback As Exception Trace.WriteLine(exRollback.Message) End Try Finally sqlTran.Commit() End Try

D.
Catch ex As Exception sqlTran.Rollback() Trace.WriteLine(ex.Message) Finally Try sqlTran.Commit() Catch exCommit As Exception Trace.WriteLine(exCommit.Message) End Try End Try



Leave a Reply 0

Your email address will not be published. Required fields are marked *