편집

다음을 통해 공유


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
public ref class OleDbException sealed : System::Runtime::InteropServices::ExternalException
public sealed class OleDbException : System.Data.Common.DbException
[System.Serializable]
public sealed class OleDbException : System.Runtime.InteropServices.ExternalException
[System.Serializable]
public sealed class OleDbException : System.Data.Common.DbException
type OleDbException = class
    inherit DbException
[<System.Serializable>]
type OleDbException = class
    inherit ExternalException
[<System.Serializable>]
type OleDbException = class
    inherit DbException
Public NotInheritable Class OleDbException
Inherits DbException
Public NotInheritable Class OleDbException
Inherits ExternalException
Inheritance
OleDbException
Inheritance
Inheritance
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 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

BatchCommand

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)
DbBatchCommand

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)
ErrorCode

Gets the HRESULT of the error.

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

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)
InnerException

Gets the Exception instance that caused the current exception.

(Inherited from Exception)
IsTransient

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 the text describing the error.

Message

Gets a message that describes the current exception.

(Inherited from Exception)
Source

Gets the name of the OLE DB provider that generated the error.

Source

Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
SqlState

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 null.

(Inherited from DbException)
StackTrace

Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite

Gets the method that throws the current exception.

(Inherited from Exception)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException()

When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)
Obsolete.

This member overrides GetObjectData(SerializationInfo, StreamingContext).

GetType()

Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Creates and returns a string representation of the current exception.

(Inherited from Exception)
ToString()

Returns a string that contains the HRESULT of the error.

(Inherited from ExternalException)

Events

SerializeObjectState
Obsolete.

Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

Applies to

See also