OdbcException.Source Eigenschaft

Definition

Ruft den Namen des ODBC-Treibers ab, der den Fehler generiert hat.Gets the name of the ODBC driver that generated the error.

public:
 virtual property System::String ^ Source { System::String ^ get(); };
public override string Source { get; }
member this.Source : string
Public Overrides ReadOnly Property Source As String

Eigenschaftswert

Der Name des ODBC-Treibers, der den Fehler generiert hat.The name of the ODBC driver that generated the error.

Beispiele

Im folgenden Beispiel werden die MessageEigenschaften Source, und NativeError des ersten OdbcError in der OdbcErrorCollection -Auflistung angezeigt.The following example displays the Message, Source, and NativeError properties of the first OdbcError within the OdbcErrorCollection collection.

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 errorMessage = "Message: " + e.Message + "\n" +
                           "Source: " + e.Source;

     System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
     log.Source = "My Application";
     log.WriteEntry(errorMessage);
     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 errorMessage As String = "Message: " & e.Message & vbCrLf & _
                                     "Source: " & e.Source

       Dim log As New System.Diagnostics.EventLog()
       log.Source = "My Application"
       log.WriteEntry(errorMessage)
       Console.WriteLine("An exception occurred. Please contact your system administrator.")
    End Try
End Sub

Hinweise

Dies ist ein Wrapper für die Source -Eigenschaft der ersten OdbcError in der Errors -Auflistung.This is a wrapper for the Source property of the first OdbcError in the Errors collection.

Gilt für:

Siehe auch