OdbcConnection.DataSource 属性

定义

获取数据源的服务器名或文件名。

public:
 virtual property System::String ^ DataSource { System::String ^ get(); };
public:
 property System::String ^ DataSource { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public override string DataSource { get; }
public string DataSource { get; }
[<System.ComponentModel.Browsable(false)>]
member this.DataSource : string
member this.DataSource : string
Public Overrides ReadOnly Property DataSource As String
Public ReadOnly Property DataSource As String

属性值

数据源的服务器名或文件名。 在打开连接前,默认值一直为空字符串 ("")。

属性

示例

以下示例创建 OdbcConnection 并显示后端数据源名称。

public void CreateOdbcConnection()
{
    string connectionString = "Driver={SQL Native Client};Server=(local);Trusted_Connection=Yes;Database=AdventureWorks;";

    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        connection.Open();
        Console.WriteLine("ServerVersion: " + connection.ServerVersion
            + "\nDatabase: " + connection.Database);

        // The connection is automatically closed at
        // the end of the Using block.
    }
}
Public Sub CreateOdbcConnection(connectionString As String)
       Using connection As New OdbcConnection(connectionString)
           With connection
               .Open()
               Console.WriteLine("ServerVersion: " & .ServerVersion _
                  & vbCrLf + "Database: " & .Database)
           End With
       End Using 
End Sub

注解

检索 DataSource 属性等效于调用将 参数设置为 SQL_SERVER_NAME 的 ODBC 函数SQLGetInfoInfoType

适用于

另请参阅