OdbcException.Source 属性
获取生成错误的 ODBC 驱动程序的名称。
**命名空间:**System.Data.Odbc
**程序集:**System.Data(在 system.data.dll 中)
语法
声明
Public Overrides ReadOnly Property Source As String
用法
Dim instance As OdbcException
Dim value As String
value = instance.Source
public override string Source { get; }
public:
virtual property String^ Source {
String^ get () override;
}
/** @property */
public String get_Source ()
public override function get Source () : String
属性值
生成错误的 ODBC 驱动程序名称。
备注
这是 Errors 集合中第一个 OdbcError 的 Source 属性的包装。
示例
下面的示例显示了 OdbcErrorCollection 集合中第一个 OdbcError 的 Message、Source 和 NativeError 属性。
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 System.Diagnostics.EventLog = 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
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.");
}
}
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1
请参见
参考
OdbcException 类
OdbcException 成员
System.Data.Odbc 命名空间