Export (0) Print
Expand All

OracleConnectionStringBuilder Class

Note: This class is new in the .NET Framework version 2.0.

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

Namespace: System.Data.OracleClient
Assembly: System.Data.OracleClient (in system.data.oracleclient.dll)

public ref class OracleConnectionStringBuilder sealed : public DbConnectionStringBuilder
public final class OracleConnectionStringBuilder extends DbConnectionStringBuilder
public final class OracleConnectionStringBuilder extends DbConnectionStringBuilder

The connection string builders allow developers to programmatically create syntactically correct connection strings, and to 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 Oracle. The OracleConnectionStringBuilder class implements the ICustomTypeDescriptor interface. This means that the class works with Visual Studio .NET designers at design time. When developers use the designer to build strongly typed DataSets and strongly typed connections within Visual Studio .NET, the strongly typed connection string builder class will display the properties associated with its type and will also have converters that can map common values for known keys.

Developers needing to create connection strings as part of applications can use the OracleConnectionStringBuilder class to build and modify connection strings. The OracleConnectionStringBuilder class also makes it easy to manage connection strings stored in an application configuration file.

The OracleConnectionStringBuilder performs checks for valid key/value pairs. Therefore, this class cannot be used to create invalid connection strings. Trying to add invalid pairs will throw an exception. The OracleConnectionStringBuilder class maintains a fixed collection of synonyms, and when required, can perform the required translation to convert from a synonym to the corresponding well-known key name. For example, when you use the Item property to retrieve a value, you can specify a string that contains any synonym for the key you need. See the Item property for a full list of acceptable synonyms.

The OracleConnectionStringBuilder handles attempts to insert malicious entries. 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. _
    OracleClient.OracleConnectionStringBuilder
builder("Data Source") = "OracleDemo"
builder("Integrated Security") = True
builder("User ID") = "Mary;NewValue=Bad"
System.Diagnostics.Debug.WriteLine(builder.ConnectionString)

[C#]

System.Data.OracleClient.OracleConnectionStringBuilder builder =
   new System.Data.OracleClient.OracleConnectionStringBuilder();
builder["Data Source"] = "OracleDemo";
builder["integrated Security"] = true;
builder["User ID"] = "Mary;NewValue=Bad";
System.Diagnostics.Debug.WriteLine(builder.ConnectionString);

The result is the following connection string that handles the invalid value in a safe manner by enclosing the User ID value in quotes:

Data Source=OracleDemo;Integrated Security=True;User ID="Mary;NewValue=Bad"

The following console application builds connection strings for an Oracle database. The code uses an OracleConnectionStringBuilder class to create the connection string, and then passes the ConnectionString property of the OracleConnectionStringBuilder instance to the constructor of the connection class. The example also parses an existing connection string, and demonstrates various ways of manipulating the connection string's contents.

NoteNote

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

System.Object
   System.Data.Common.DbConnectionStringBuilder
    System.Data.OracleClient.OracleConnectionStringBuilder

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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft