Export (0) Print
Expand All

SqlConnectionStringBuilder Constructor (String)

Initializes a new instance of the SqlConnectionStringBuilder class. The provided connection string provides the data for the instance's internal connection information.

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

public:
SqlConnectionStringBuilder(
	String^ connectionString
)

Parameters

connectionString
Type: System::String

The basis for the object's internal connection information. Parsed into name/value pairs. Invalid key names raise KeyNotFoundException.

ExceptionCondition
KeyNotFoundException

Invalid key name within the connection string.

FormatException

Invalid value within the connection string (specifically, when a Boolean or numeric value was expected but not supplied).

ArgumentException

The supplied connectionString is not valid.

The SqlConnectionStringBuilder class provides a fixed internal collection of key/value pairs. Even if you supply only a small subset of the possible connection string values in the constructor, the object always provides default values for each key/value pair. When the ConnectionString property of the object is retrieved, the string contains only key/value pairs in which the value is not the default value for the item.

The following example supplies a simple SQL Server connection string in the SqlConnectionStringBuilder object's constructor, and then iterates through all the key/value pairs within the object. Note that the collection provides default values for each item. Also note that the SqlConnectionStringBuilder class converts synonyms for the well-known keys so that they are consistent with the well-known names.

NoteNote

This example includes a password to demonstrate how SqlConnectionStringBuilder 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