OleDbException Class
The exception that is thrown when the underlying provider returns a warning or error for an OLE DB data source. This class cannot be inherited.
Assembly: System.Data (in System.Data.dll)
This class is created whenever the .NET Framework Data Provider for OLE DB encounters an error generated from the server. (Client side errors are thrown as standard common language runtime exceptions.) OleDbException 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.
For general information about handling exceptions for a .NET Framework data provider, see SqlException.
The following example generates an OleDbException because of a missing data source, and then displays the exception.
Public Sub ShowOleDbException() Dim mySelectQuery As String = "SELECT column1 FROM table1" Dim myConnection As New OleDbConnection _ ("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=") Dim myCommand As New OleDbCommand(mySelectQuery, myConnection) Try myCommand.Connection.Open() Catch e As OleDbException Dim errorMessages As String Dim i As Integer For i = 0 To e.Errors.Count - 1 errorMessages += "Index #" & i.ToString() & ControlChars.Cr _ & "Message: " & e.Errors(i).Message & ControlChars.Cr _ & "NativeError: " & e.Errors(i).NativeError & ControlChars.Cr _ & "Source: " & e.Errors(i).Source & ControlChars.Cr _ & "SQLState: " & e.Errors(i).SQLState & ControlChars.Cr Next i Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog() log.Source = "My Application" log.WriteEntry(errorMessages) Console.WriteLine("An exception occurred. Please contact your system administrator.") End Try End Sub
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
System.Data.Common.DbException
System.Data.OleDb.OleDbException
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.