共用方式為


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擷取屬性相當於呼叫 ODBC 函SQLGetInfo式,InfoType並將 參數設定為 SQL_SERVER_NAME。

適用於

另請參閱