System.Data.OleDb Namespace
The exception that is thrown when a warning or error is returned by an OLE DB data source.
This class is created whenever the OleDb adapter encounters a situation that it cannot handle. It always contains at least one instance of OleDbError.
If the severity of the error is too great, the server may close the OleDbConnection. However, the user can reopen the connection and continue.
The following example generates an OleDbException due to a missing data source, and then displays the exception.
[ VB ]
Public Sub ThrowOleDbException ( )
Dim query As String = "SELECT column1 FROM table1"
Dim myConn As New OleDbConnection _
( "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=" )
Dim myCommand As New OleDbCommand ( query, myConn )
Try
myCommand.Connection.Open ( )
Catch myException As OleDbException
Dim i As Integer
For i = 0 To myException.Errors.Count - 1
Response.Write ( "Index #" + i.ToString ( ) + ControlChars.Cr _
+ "Message: " + myException.Errors ( i ).Message + ControlChars.Cr _
+ "Native: " + myException.Errors ( i ).NativeError.ToString ( ) + ControlChars.Cr _
+ "Source: " + myException.Errors ( i ).Source + ControlChars.Cr _
+ "SQL: " + myException.Errors ( i ).SQLState + ControlChars.Cr )
Next i
End Try
End Sub
[ C# ]
void ThrowOleDbException ( )
{
string query = "SELECT column1 FROM table1";
OleDbConnection myConn =
new OleDbConnection ( "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=" );
OleDbCommand myCommand = new OleDbCommand ( query, myConn );
try
{
myCommand.Connection.Open ( );
}
catch ( OleDbException myException )
{
for ( int i=0; i < myException.Errors.Count; i++ )
{
Response.Write ( "Index #" + i + "<br>" +
"Message: " + myException.Errors [ ].Message + "<br>" +
"Native: " + myException.Errors [ ].NativeError.ToString ( ) + "<br>" +
"Source: " + myException.Errors [ ].Source + "<br>" +
"SQL: " + myException.Errors [ ].SQLState + "<br>" );
}
}
}
OleDbError OleDbErrorCollection