共用方式為


IDbConnection.ConnectionString 屬性

定義

取得或設定用來開啟資料庫的字串。

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

屬性值

包含連線設定的字串。

範例

下列範例會建立衍生類別的實例、 OleDbConnection設定其 ConnectionString,並顯示其 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只有在關閉連接時,才能設定 屬性。

適用於