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

属性值

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仅当连接关闭时,才能设置该属性。

适用于