OdbcException Class
The exception that is generated when a warning or error is returned by an ODBC data source. This class cannot be inherited.
Assembly: System.Data (in System.Data.dll)
This class is created whenever the OdbcDataAdapter encounters an error generated by the server (Client-side errors are raised as standard common language runtime exceptions.). It always contains at least one instance of OdbcError.
If the severity of the error is too great, the server may close the OdbcConnection. 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 OdbcException because of a missing data source, and then displays the exception.
Public Sub ShowOdbcException() Dim mySelectQuery As String = "SELECT column1 FROM table1" Dim myConnection As New OdbcConnection _ ("DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;") Dim myCommand As New OdbcCommand(mySelectQuery, myConnection) Try myCommand.Connection.Open() Catch e As OdbcException 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.ToString() & ControlChars.Cr _ & "Source: " & e.Errors(i).Source & ControlChars.Cr _ & "SQL: " & 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.Odbc.OdbcException
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.