OleDbException
OleDbException
OleDbException
OleDbException
Class
Definition
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.
public ref class OleDbException sealed : System::Data::Common::DbException
[System.Serializable]
public sealed class OleDbException : System.Data.Common.DbException
type OleDbException = class
inherit DbException
Public NotInheritable Class OleDbException
Inherits DbException
- Inheritance
-
OleDbExceptionOleDbExceptionOleDbExceptionOleDbException
- Attributes
Examples
The following example generates an OleDbException because of a missing data source, and then displays the exception.
public void ShowOleDbException()
{
string mySelectQuery = "SELECT column1 FROM table1";
OleDbConnection myConnection =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=");
OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConnection);
try
{
myCommand.Connection.Open();
}
catch (OleDbException 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 + "\n" +
"Source: " + e.Errors[i].Source + "\n" +
"SQLState: " + 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 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
Remarks
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.
Properties
Data Data Data Data |
Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Inherited from Exception) |
ErrorCode ErrorCode ErrorCode ErrorCode |
Gets the HRESULT of the error. |
Errors Errors Errors Errors |
Gets a collection of one or more OleDbError objects that give detailed information about exceptions generated by the .NET Framework Data Provider for OLE DB. |
HelpLink HelpLink HelpLink HelpLink |
Gets or sets a link to the help file associated with this exception. (Inherited from Exception) |
HResult HResult HResult HResult |
Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Inherited from Exception) |
InnerException InnerException InnerException InnerException |
Gets the Exception instance that caused the current exception. (Inherited from Exception) |
Message Message Message Message | |
Source Source Source Source | |
StackTrace StackTrace StackTrace StackTrace |
Gets a string representation of the immediate frames on the call stack. (Inherited from Exception) |
TargetSite TargetSite TargetSite TargetSite |
Gets the method that throws the current exception. (Inherited from Exception) |
Methods
Events
SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState |
Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception) |