Bagikan melalui


OdbcConnection.DataSource Properti

Definisi

Mendapatkan nama server atau nama file sumber data.

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

Nilai Properti

Nama server atau nama file sumber data. Nilai default adalah string kosong ("") hingga koneksi dibuka.

Atribut

Contoh

Contoh berikut membuat OdbcConnection dan menampilkan nama sumber data backend.

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

Keterangan

Mengambil DataSource properti setara dengan memanggil fungsi SQLGetInfo ODBC dengan parameter yang InfoType diatur ke SQL_SERVER_NAME.

Berlaku untuk

Lihat juga