IDbConnection.ConnectionString 屬性

定義

取得或設定用來開啟資料庫的字串。Gets or sets the string used to open a database.

public:
 property System::String ^ ConnectionString { System::String ^ get(); void set(System::String ^ value); };
public string ConnectionString { get; set; }
member this.ConnectionString : string with get, set
Public Property ConnectionString As String

屬性值

String

包含連線設定的字串。A string containing connection settings.

範例

下列範例會建立衍生類別的實例、 OleDbConnection 設定它的 ConnectionString ,並顯示其 StateThe following example creates an instance of a derived class, OleDbConnection, sets its ConnectionString, and displays its State.

public void CreateOleDbConnection(){
   OleDbConnection connection = new OleDbConnection();
   connection.ConnectionString =
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb";
   Console.WriteLine("Connection State: " + connection.State.ToString());
}
Public Sub CreateOleDbConnection()
    Dim connection As New OleDbConnection()
    connection.ConnectionString = _
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb"
    Console.WriteLine("Connection State: " & connection.State.ToString())
End Sub

備註

ConnectionString只有在連接關閉時,才能設定屬性。The ConnectionString property can be set only while the connection is closed.

適用於