Export (0) Print
Expand All

IDbConnection.ConnectionString Property

Gets or sets the string used to open a database.

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

Property Value

A string containing connection settings.

Remarks

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

Example

[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

[C#] 
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());
}

[C++] 
public:
 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.

Requirements

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

Show:
© 2014 Microsoft