Export (0) Print
Expand All

DbConnectionStringBuilder.ConnectionString Property

Gets or sets the connection string associated with the DbConnectionStringBuilder.

Namespace:  System.Data.Common
Assembly:  System.Data (in System.Data.dll)

member ConnectionString : string with get, set

Property Value

Type: System.String
The current connection string, created from the key/value pairs that are contained within the DbConnectionStringBuilder. The default value is an empty string.

ExceptionCondition
ArgumentException

An invalid connection string argument has been supplied.

This property returns a semicolon-delimited list of key/value pairs stored within the collection maintained by the DbConnectionStringBuilder. Each pair contains the key and value, separated by an equal sign. The following example illustrates a typical connection string.

"Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=AdventureWorks;Data Source=(local)"

Data providers may expect specific keys and values for each connection string property. , These values are documented individually. The DbConnectionStringBuilder class does not validate the key/value pairs associated with its connection string, although classes that inherit from it can.

The ConnectionString property of the DbConnectionStringBuilder class acts generally as a mechanism for creating and parsing semicolon-delimited lists of key/value pairs separated with equal signs. It provides no validation or other support specific to connection strings. If you add items to the DbConnectionStringBuilder collection, the ConnectionString property will reflect the changes. If you assign a value to the ConnectionString property, the DbConnectionStringBuilder will try to parse the value, using the semicolon and equal-sign delimiters.

The following example demonstrates possible behaviors of the ConnectionString property. The example:

  • Creates a connection string by adding key/value pairs, one at a time, to an empty DbConnectionStringBuilder.

  • Assigns a complete connection string to the ConnectionString property of the DbConnectionStringBuilder instance, and modifies a single key/value pair within the string.

  • Assigns an arbitrary set of key/value pairs to the ConnectionString property (that is, a string that is not anything remotely like a connection string), and modifies one of the values.

  • Assigns an invalid connection string to the ConnectionString property, demonstrating the exception that is thrown.

NoteNote

This example includes a password to demonstrate how DbConnectionStringBuilder works with connection strings. In your applications, we recommend that you use Windows Authentication. If you must use a password, do not include a hard-coded password in your application.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft