OdbcException.Source 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得產生錯誤的 ODBC 驅動程式名稱。
public:
virtual property System::String ^ Source { System::String ^ get(); };
C#
public override string Source { get; }
member this.Source : string
Public Overrides ReadOnly Property Source As String
產生錯誤的 ODBC 驅動程式名稱。
下列範例會顯示Message集合中OdbcErrorCollection第一個 OdbcError 的、 Source和 NativeError 屬性。
C#
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
這是集合中Errors第一個 OdbcError 屬性的包裝函Source式。
產品 | 版本 |
---|---|
.NET | 8 (package-provided), 9 (package-provided), 10 (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, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |