OdbcException Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
The exception that is generated when a warning or error is returned by an ODBC data source. This class cannot be inherited.
public ref class OdbcException sealed : System::Data::Common::DbException
public ref class OdbcException sealed : SystemException
public sealed class OdbcException : System.Data.Common.DbException
[System.Serializable]
public sealed class OdbcException : SystemException
[System.Serializable]
public sealed class OdbcException : System.Data.Common.DbException
type OdbcException = class
inherit DbException
[<System.Serializable>]
type OdbcException = class
inherit SystemException
[<System.Serializable>]
type OdbcException = class
inherit DbException
Public NotInheritable Class OdbcException
Inherits DbException
Public NotInheritable Class OdbcException
Inherits SystemException
- Inheritance
- Inheritance
- Inheritance
- Attributes
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.");
}
}
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 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
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.
Batch |
If this DbException was thrown when executing a DbBatch, references the specific DbBatchCommand which triggered the exception. (Inherited from DbException) |
Data |
Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Inherited from Exception) |
Db |
When overridden in a derived class, if this DbException was thrown when executing a DbBatch, references the specific DbBatchCommand which triggered the exception. (Inherited from DbException) |
Error |
Gets the |
Errors |
Gets a collection of one or more OdbcError objects that give detailed information about exceptions generated by the .NET Framework Data Provider for ODBC. |
Help |
Gets or sets a link to the help file associated with this exception. (Inherited from Exception) |
HResult |
Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Inherited from Exception) |
Inner |
Gets the Exception instance that caused the current exception. (Inherited from Exception) |
Is |
Indicates whether the error represented by this DbException could be a transient error, i.e. if retrying the triggering operation may succeed without any other change. (Inherited from DbException) |
Message |
Gets a message that describes the current exception. |
Message |
Gets a message that describes the current exception. (Inherited from Exception) |
Source |
Gets the name of the ODBC driver that generated the error. |
Sql |
For database providers which support it, contains a standard SQL 5-character return code indicating the success or failure of the database operation. The first 2 characters represent the class of the return code (e.g. error, success), while the last 3 characters represent the subclass, allowing detection of error scenarios in a database-portable way. For database providers which don't support it, or for inapplicable error scenarios, contains |
Stack |
Gets a string representation of the immediate frames on the call stack. (Inherited from Exception) |
Target |
Gets the method that throws the current exception. (Inherited from Exception) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Inherited from Exception) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Obsolete.
This member overrides GetObjectData(SerializationInfo, StreamingContext). |
Get |
Gets the runtime type of the current instance. (Inherited from Exception) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Creates and returns a string representation of the current exception. (Inherited from Exception) |
To |
Returns a string that contains the HRESULT of the error. (Inherited from ExternalException) |
Serialize |
Obsolete.
Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception) |
Termék | Verziók |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET-visszajelzés
A(z) .NET egy nyílt forráskód projekt. Visszajelzés adásához válasszon egy hivatkozást: