OdbcException Class
Assembly: System.Data (in system.data.dll)
'Declaration <SerializableAttribute> _ Public NotInheritable Class OdbcException Inherits DbException 'Usage Dim instance As OdbcException
/** @attribute SerializableAttribute() */ public final class OdbcException extends DbException
SerializableAttribute public final class OdbcException extends DbException
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.
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 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.