OdbcConnectionStringBuilder Class

 

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

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

System::Object
  System.Data.Common::DbConnectionStringBuilder
    System.Data.Odbc::OdbcConnectionStringBuilder

public ref class OdbcConnectionStringBuilder sealed : DbConnectionStringBuilder

NameDescription
System_CAPS_pubmethodOdbcConnectionStringBuilder()

Initializes a new instance of the OdbcConnectionStringBuilder class.

System_CAPS_pubmethodOdbcConnectionStringBuilder(String^)

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

NameDescription
System_CAPS_pubpropertyBrowsableConnectionString

Gets or sets a value that indicates whether the ConnectionString property is visible in Visual Studio designers.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubpropertyConnectionString

Gets or sets the connection string associated with the DbConnectionStringBuilder.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubpropertyCount

Gets the current number of keys that are contained within the ConnectionString property.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubpropertyDriver

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

System_CAPS_pubpropertyDsn

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

System_CAPS_pubpropertyIsFixedSize

Gets a value that indicates whether the DbConnectionStringBuilder has a fixed size.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the DbConnectionStringBuilder is read-only.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubpropertyItem[String^]

Gets or sets the value associated with the specified key. In C#, this property is the indexer.(Overrides DbConnectionStringBuilder::Item[String^].)

System_CAPS_pubpropertyKeys

Gets an ICollection that contains the keys in the OdbcConnectionStringBuilder.(Overrides DbConnectionStringBuilder::Keys.)

System_CAPS_pubpropertyValues

Gets an ICollection that contains the values in the DbConnectionStringBuilder.(Inherited from DbConnectionStringBuilder.)

NameDescription
System_CAPS_pubmethodAdd(String^, Object^)

Adds an entry with the specified key and value into the DbConnectionStringBuilder.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubmethodClear()

Clears the contents of the OdbcConnectionStringBuilder instance.(Overrides DbConnectionStringBuilder::Clear().)

System_CAPS_protmethodClearPropertyDescriptors()

Clears the collection of PropertyDescriptor objects on the associated DbConnectionStringBuilder.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubmethodContainsKey(String^)

Determines whether the OdbcConnectionStringBuilder contains a specific key.(Overrides DbConnectionStringBuilder::ContainsKey(String^).)

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodEquivalentTo(DbConnectionStringBuilder^)

Compares the connection information in this DbConnectionStringBuilder object with the connection information in the supplied object.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodRemove(String^)

Removes the entry with the specified key from the OdbcConnectionStringBuilder instance.(Overrides DbConnectionStringBuilder::Remove(String^).)

System_CAPS_pubmethodShouldSerialize(String^)

Indicates whether the specified key exists in this DbConnectionStringBuilder instance.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubmethodToString()

Returns the connection string associated with this DbConnectionStringBuilder.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubmethodTryGetValue(String^, Object^%)

Retrieves a value corresponding to the supplied key from this OdbcConnectionStringBuilder.(Overrides DbConnectionStringBuilder::TryGetValue(String^, Object^%).)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection::CopyTo(Array^, Int32)

Copies the elements of the ICollection to an Array, starting at a particular Array index.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary::Add(Object^, Object^)

Adds an element with the provided key and value to the IDictionary object.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary::Contains(Object^)

Determines whether the IDictionary object contains an element with the specified key.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary::GetEnumerator()

Returns an IDictionaryEnumerator object for the IDictionary object.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary::Remove(Object^)

Removes the element with the specified key from the IDictionary object.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable::GetEnumerator()

Returns an enumerator that iterates through a collection.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetAttributes()

Returns a collection of custom attributes for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetClassName()

Returns the class name of this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetComponentName()

Returns the name of this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetConverter()

Returns a type converter for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetDefaultEvent()

Returns the default event for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetDefaultProperty()

Returns the default property for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetEditor(Type^)

Returns an editor of the specified type for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetEvents()

Returns the events for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetEvents(array<Attribute^>^)

Returns the events for this instance of a component using the specified attribute array as a filter.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetProperties()

Returns the properties for this instance of a component.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetProperties(array<Attribute^>^)

Returns the properties for this instance of a component using the attribute array as a filter.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICustomTypeDescriptor::GetPropertyOwner(PropertyDescriptor^)

Returns an object that contains the property described by the specified property descriptor.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection::IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection::SyncRoot

Gets an object that can be used to synchronize access to the ICollection.(Inherited from DbConnectionStringBuilder.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary::Item[Object^]

Gets or sets the element with the specified key.(Inherited from DbConnectionStringBuilder.)

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

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 OdbcConnectionStringBuilder class to build and modify connection strings. The class also makes it easy to manage connection strings stored in an application configuration file. OdbcConnectionStringBuilder 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 OdbcConnectionStringBuilder class, and their default values. Besides these specific values, developers can add any key/value pairs to the collection that is contained within the OdbcConnectionStringBuilder instance.

Key

Property

Comment

Default value

Driver

Driver

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

Empty string

DSN

Dsn

Empty string

If any value (other than the Driver value) within the connection string contains a semicolon (;), the OdbcConnectionStringBuilder surrounds the value with quotation marks in the connection string. In order to avoid this issue with the Driver value that frequently contains a semicolon, the OdbcConnectionStringBuilder 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 Item property handles attempts to insert malicious code. For example, the following code, using the default Item 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"

The following console application builds connection strings for several ODBC databases. First, the example creates a connection string for a Microsoft Access database. It then creates a connection string for an IBM DB2 database. The example also parses an existing connection string, and demonstrates various ways of manipulating the contents of the connection string.

System_CAPS_noteNote

This example includes a password to demonstrate how OdbcConnectionStringBuilder 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
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: