nerdexam
Microsoft

70-516 · Question #222

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…

The correct answer is C. Catch ex As DbException. 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…

Deploying and Troubleshooting Data Access

Question

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() 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?

Options

  • ACatch ex As OleDbException
  • BCatch ex As OleDbException
  • CCatch ex As DbException
  • DCatch ex As DbException

How the community answered

(30 responses)
  • A
    7% (2)
  • B
    17% (5)
  • C
    73% (22)
  • D
    3% (1)

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.

Topics

#DbException#database-independent DAL#DbConnection#exception handling

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice