OdbcException Class
.NET Framework 3.0
The exception that is generated when a warning or error is returned by an ODBC data source. This class cannot be inherited.
Namespace: System.Data.Odbc
Assembly: System.Data (in system.data.dll)
System.Data.Odbc Namespace
OdbcErrorCollection
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.
The following example generates an OdbcException because of a missing data source, and then displays the exception.
public void ShowOdbcException() { string mySelectQuery = "SELECT column1 FROM table1"; OdbcConnection myConnection = new OdbcConnection("DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;"); OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection); try { myCommand.Connection.Open(); } catch (OdbcException e) { string errorMessages = ""; for (int i=0; i < e.Errors.Count; i++) { errorMessages += "Index #" + i + "\n" + "Message: " + e.Errors[i].Message + "\n" + "NativeError: " + e.Errors[i].NativeError.ToString() + "\n" + "Source: " + e.Errors[i].Source + "\n" + "SQL: " + e.Errors[i].SQLState + "\n"; } System.Diagnostics.EventLog log = new System.Diagnostics.EventLog(); log.Source = "My Application"; log.WriteEntry(errorMessages); Console.WriteLine("An exception occurred. Please contact your system administrator."); } }
System.Object
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
System.Data.Common.DbException
System.Data.Odbc.OdbcException
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
System.Data.Common.DbException
System.Data.Odbc.OdbcException
Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Reference
OdbcException MembersSystem.Data.Odbc Namespace
OdbcErrorCollection
Other Resources
Exceptions OverviewCommunity Additions
ADD
Show: