PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 09?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. You
create a Database Access Layer (DAL) that is database-independent.
The DAL includes the following code segment. (Line numbers are included for reference only.)
01 Shared Sub ExecuteDbCommand(connection As DbConnection)
02 If connection <> Nothing Then
03 Using connection
04 Try
05 connection.Open()
06 Dim command As DbCommand = connection.CreateCommand()
07 command.CommandText = “INSERT INTO Categories (CategoryName) VALUES (‘Low Carb’)”
08 command.ExecuteNonQuery()
09
10 Catch ex As Exception
11 Trace.WriteLine(“Exception.Message: ” + ex.Message)
12 End Try
13 End Using
14 End If
15 End Sub
You need to log information about any error that occurs during data access. You also need to log the
data provider that accesses the database. Which code segment should you insert at line 09?

PrepAway - Latest Free Exam Questions & Answers

A.
Catch ex As OleDbException
Trace.WriteLine(“ExceptionType: ” + ex.Source)
Trace.WriteLine(“Message: ” + ex.Message)

B.
Catch ex As OleDbException
Trace.WriteLine(“ExceptionType: ” + ex.InnerException.Source)
Trace.WriteLine(“Message: ” + ex.InnerException.Message)

C.
Catch ex As DbException
Trace.WriteLine(“ExceptionType: ” + ex.Source)
Trace.WriteLine(“Message: ” + ex.Message)

D.
Catch ex As DbException
Trace.WriteLine(“ExceptionType: ” + ex.InnerException.Source)
Trace.WriteLine(“Message: ” + ex.InnerException.Message)

Explanation:

Exception.InnerException Gets the Exception instance that caused the current exception.
Message Gets a message that describes the current exception.
Exception.Source Gets or sets the name of the application or the object that causes the error.
OleDbException catches the exception that is thrown only when the underlying provider returns a
warning or error for an OLE DB data source.
DbException catches the common exception while accessing data base.


Leave a Reply