System.Data 2.0.0.0 System.Data.Common.DbConnectionStringBuilder System.ComponentModel.TypeConverter("System.Data.Odbc.OdbcConnectionStringBuilder+OdbcConnectionStringBuilderConverter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") System.ComponentModel.DefaultProperty("Driver")

The connection string builders let developers programmatically create syntactically correct connection strings, and parse and rebuild existing connection strings, using properties and methods of the class. The connection string builder provides strongly typed properties corresponding to the known key/value pairs allowed by ODBC connections, and developers can add arbitrary key/value pairs for any other connection string values.

Developers needing to create connection strings as part of applications can use the class to build and modify connection strings. The class also makes it easy to manage connection strings stored in an application configuration file. performs checks only for the limited set of known key/value pairs. Therefore, this class can be used to create invalid connection strings. The following table lists the specific known keys together with their corresponding properties within the class, and their default values. Besides these specific values, developers can add any key/value pairs to the collection that is contained within the instance.

Key

Property

Comment

Default value

Driver

Developers should not include the braces surrounding the driver name when they set the property. The instance adds braces as needed.

Empty string

DSN

Empty string

If any value (other than the value) within the connection string contains a semicolon (;), the surrounds the value with quotation marks in the connection string. In order to avoid this issue with the value that frequently contains a semicolon, the class always surrounds this value with braces. The ODBC specification indicates that driver values that contain semicolons must be surrounded with braces, and this class handles this for you.

The property handles attempts to insert malicious code. For example, the following code, using the default property (the indexer, in C#) correctly escapes the nested key/value pair.

[Visual Basic]

`Dim builder As _ New System.Data.Odbc.OdbcConnectionStringBuilder ' Take advantage of the Driver property. builder.Driver = "SQL Server" builder("Server") = "MyServer;NewValue=Bad" Console.WriteLine(builder.ConnectionString)`

[C#]

`System.Data.Odbc.OdbcConnectionStringBuilder builder = new System.Data.Odbc.OdbcConnectionStringBuilder(); // Take advantage of the Driver property. builder.Driver = "SQL Server"; builder["Server"] = "MyServer;NewValue=Bad"; Console.WriteLine(builder.ConnectionString);`

The result is the following connection string that handles the invalid value in a safe manner:

`Driver={SQL Server};Server="MyServer;NewValue=Bad"`

Provides a simple way to create and manage the contents of connection strings used by the class.

- Constructor
  2.0.0.0
  To be added.

  Initializes a new instance of the class.

- Constructor
  2.0.0.0

  You can pass a connection string in the constructor, or you can set the property explicitly. The behavior is the same either way.

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

  The basis for the object's internal connection information. Parsed into key/value pairs.
- Method
  2.0.0.0
  System.Void

  The method removes all key/value pairs from the and resets the and properties to their default values. The method also sets the property to 0 and the property to an empty string.

  Clears the contents of the instance.

- Method
  2.0.0.0
  System.Boolean `` To be added.

  Determines whether the contains a specific key.

  true if the contains an element that has the specified key; otherwise false.

  The key to locate in the .
- Property
  2.0.0.0
  System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)
  System.ComponentModel.DisplayName("Driver")
  System.String To be added.

  If the value passed in is null when you try to set the property, the property is reset. If the value has not been set and the developer tries to retrieve the property, the return value is String.Empty. This property corresponds to the "Driver" key within the connection string.

  Gets or sets the name of the ODBC driver associated with the connection.

- Property
  2.0.0.0
  System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)
  System.ComponentModel.DisplayName("Dsn")
  System.String To be added.

  If the value passed in is null when you try to set the property, the property is reset. If the value has not been set and the developer tries to retrieve the property, the return value is String.Empty. This property corresponds to the "Dsn" key within the connection string.

  Gets or sets the name of the data source name (DSN) associated with the connection.

- Property
  2.0.0.0
  System.Object `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  System.Collections.ICollection To be added.

  The order of the values in the is the same order as the associated values in the returned by the property.

  Gets an that contains the keys in the .

- Method
  2.0.0.0
  System.Boolean ``

  Because the method returns a value that indicates its success, it is not required to look for the existence of a key before trying to remove the key/value pair from the instance.

  Removes the entry with the specified key from the instance.

  true if the key existed within the connection string and was removed; false if the key did not exist.

  The key of the key/value pair to be removed from the connection string in this .
- Method
  2.0.0.0
  System.Boolean `` `` To be added. To be added. To be added. To be added. To be added.