This documentation is archived and is not being maintained.

IDbConnection.ConnectionString Property

Gets or sets the string used to open a database.

[Visual Basic]
Property ConnectionString As String
string ConnectionString {get; set;}
__property String* get_ConnectionString();
__property void set_ConnectionString(String*);
function get ConnectionString() : String;function set ConnectionString(String);

Property Value

A string containing connection settings.


The ConnectionString property can be set only while the connection is closed.


[Visual Basic, C#, C++] The following example creates an instance of a derived class, OleDbConnection, sets its ConnectionString, and displays its State. .

[Visual Basic] 
Public Sub createOleDbConnection()
    Dim myConnection As New OleDbConnection()
    myConnection.ConnectionString = _
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB"
    MessageBox.Show("Connection State: " + myConnection.State.ToString())
End Sub

public void createOleDbConnection(){
   OleDbConnection myConnection = new OleDbConnection();
   myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB";
   MessageBox.Show("Connection State: " + myConnection.State.ToString());

 void createOleDbConnection(){
    OleDbConnection* myConnection = new OleDbConnection();
    myConnection->ConnectionString = S"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB";
    MessageBox::Show(String::Format( S"Connection State: {0}", __box(myConnection->State)));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

IDbConnection Interface | IDbConnection Members | System.Data Namespace