Bagikan melalui


OleDbConnection.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(true)]
public override string DataSource { get; }
[System.Data.DataSysDescription("OleDbConnection_DataSource")]
public string DataSource { get; }
[<System.ComponentModel.Browsable(true)>]
member this.DataSource : string
[<System.Data.DataSysDescription("OleDbConnection_DataSource")>]
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-nya adalah untaian kosong.

Atribut

Contoh

Contoh berikut membuat OleDbConnection dan menampilkan beberapa properti baca-saja.

static void OpenConnection(string connectionString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        try
        {
            connection.Open();
            Console.WriteLine("ServerVersion: {0} \nDataSource: {1}",
                connection.ServerVersion, connection.DataSource);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}
Public Sub OpenConnection(ByVal connectionString As String)

    Using connection As New OleDbConnection(connectionString)
        Try
            connection.Open()
            Console.WriteLine("Server Version: {0} DataSource: {1}", _
                connection.ServerVersion, connection.DataSource)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using
End Sub

Keterangan

Jika koneksi ke database ditutup, DataSource properti mengembalikan apa pun yang ada di ConnectionString dalamnya untuk kata kunci sumber data. Jika koneksi terbuka dan ConnectionString nilai kata kunci sumber data dimulai dengan "|datadirectory|", properti mengembalikan apa pun yang ada di ConnectionString kata kunci sumber data saja. Jika koneksi ke database terbuka, properti mengembalikan apa yang dikembalikan penyedia asli untuk DBPROP_INIT_DATASOURCE, dan jika kosong, penyedia DBPROP_DATASOURCENAME asli dikembalikan.

Berlaku untuk

Lihat juga