OleDbException OleDbException OleDbException OleDbException Class

定义

在基础提供程序返回 OLE DB 数据源的警告或错误时引发的异常。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
继承
属性

示例

下面的示例生成OleDbException ,因为缺少数据源,并显示异常。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

注解

每当用于 OLE DB 的 .NET Framework 数据提供程序遇到服务器生成的错误时,就会创建此类。This class is created whenever the .NET Framework Data Provider for OLE DB encounters an error generated from the server. (客户端错误作为标准公共语言运行时异常引发。)始终至少包含一个OleDbError实例。 OleDbException(Client side errors are thrown as standard common language runtime exceptions.) OleDbException always contains at least one instance of OleDbError.

如果错误的严重程度太高,服务器可能会关闭 OleDbConnectionIf the severity of the error is too great, the server may close the OleDbConnection. 但是,用户可以重新打开连接并继续操作。However, the user can reopen the connection and continue.

有关处理 .NET Framework 数据提供程序的异常的常规信息,请SqlException参阅。For general information about handling exceptions for a .NET Framework data provider, see SqlException.

属性

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

获取错误的 HRESULT。Gets the HRESULT of the error.

Errors Errors Errors Errors

获取一个或多个 OleDbError 对象集合,这些对象提供有关用于 OLE DB 的 .NET Framework 数据提供程序生成的异常的详细信息。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

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

获取对错误进行描述的文本。Gets the text describing the error.

Source Source Source Source

获取生成错误的 OLE DB 提供程序的名称。Gets the name of the OLE DB provider that generated the error.

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)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

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

此成员重写 GetObjectData(SerializationInfo, StreamingContext)This member overrides GetObjectData(SerializationInfo, StreamingContext).

GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回一个字符串,该字符串包含错误的 HRESULT。Returns a string that contains the HRESULT of the error.

(Inherited from ExternalException)

事件

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)

适用于

另请参阅