Bagikan melalui


SqlConnection.Database Properti

Definisi

Mendapatkan nama database saat ini atau database yang akan digunakan setelah koneksi dibuka.

public:
 virtual property System::String ^ Database { System::String ^ get(); };
public:
 property System::String ^ Database { System::String ^ get(); };
public override string Database { get; }
[System.Data.DataSysDescription("SqlConnection_Database")]
public string Database { get; }
member this.Database : string
[<System.Data.DataSysDescription("SqlConnection_Database")>]
member this.Database : string
Public Overrides ReadOnly Property Database As String
Public ReadOnly Property Database As String

Nilai Properti

Nama database saat ini atau nama database yang akan digunakan setelah koneksi dibuka. Nilai default-nya adalah untaian kosong.

Penerapan

Atribut

Contoh

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

private static void ChangeSqlDatabase(string connectionString)
{
    // Assumes connectionString represents a valid connection string
    // to the AdventureWorks sample database.
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine("Database: {0}", connection.Database);

        connection.ChangeDatabase("Northwind");
        Console.WriteLine("Database: {0}", connection.Database);
    }
}
Private Sub ChangeSqlDatabase(ByVal connectionString As String)
    ' Assumes connectionString represents a valid connection string
    ' to the AdventureWorks sample database.
    Using connection As New SqlConnection(connectionString)

        connection.Open()
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion)
        Console.WriteLine("Database: {0}", connection.Database)

        connection.ChangeDatabase("Northwind")
        Console.WriteLine("Database: {0}", connection.Database)
    End Using
End Sub

Keterangan

Properti diperbarui Database secara dinamis. Jika Anda mengubah database saat ini menggunakan pernyataan Transact-SQL atau ChangeDatabase metode , pesan informasi dikirim dan properti diperbarui secara otomatis.

Berlaku untuk

Lihat juga