An OracleConnectionStringBuilder object allows applications to create or modify connection strings.
Supported Only in ADO.NET 2.0-Compliant ODP.NET
System.Object
System.Data.Common.DbConnectionStringBuilder
Oracle.DataAccess.Client.OracleConnectionStringBuilder
// C# public sealed class OracleConnectionStringBuilder : DbConnectionStringBuilder
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
The following rules must be followed for setting values with reserved characters:
Values containing characters enclosed within single quotes
If the value contains characters that are enclosed within single quotation marks, then the entire value must be enclosed within double quotation marks.
For example, password = "'scoTT'" where the value is 'scoTT'.
Values containing characters enclosed within double quotes
Values should be enclosed in double quotation marks to preserve the case and to avoid the upper casing of values.
If the value contains characters enclosed in double quotation marks, then it must be enclosed in single quotation marks.
For example, password = '"scoTT"' where the value is "scoTT".
Values containing characters enclosed in both single and double quotes
If the value contains characters enclosed in both single and double quotation marks, the quotation mark used to enclose the value must be doubled each time it occurs within the value.
For example, password = '"sco''TT"' where the value is "sco'TT".
Values containing spaces
All leading and trailing spaces are ignored, but the spaces between the value are recognized. If the value needs to have leading or trailing spaces then it must be enclosed in double quotation marks.
For example, User ID = Sco TT where the value is <Sco TT>.
For example, User ID = "Sco TT " where the value is <Sco TT>.
Keywords occurring multiple times in a connection string
If a specific keyword occurs multiple times in a connection string, the last occurrence listed is used in the value set.
For example, with "User ID = scott; password = tiger; User ID = david" connection string, User ID value is david.
// C#
using System;
using System.Data;
using System.Data.Common;
using Oracle.DataAccess.Client;
using System.Collections;
class ConnectionStringBuilderSample
{
static void Main(string[] args)
{
bool bRet = false;
// Create an instance of OracleConnectionStringBuilder
OracleConnectionStringBuilder connStrBuilder =
new OracleConnectionStringBuilder();
// Add new key/value pairs to the connection string
connStrBuilder.Add("User Id", "scott");
connStrBuilder.Add("Password", "tiger");
connStrBuilder.Add("Data Source", "oracle");
connStrBuilder.Add("pooling", false);
// Modify the existing value
connStrBuilder["Data source"] = "inst1";
// Remove an entry from the connection string
bRet = connStrBuilder.Remove("pooling");
//ContainsKey indicates whether or not the specific key exist
//returns true even if the user has not specified it explicitly
Console.WriteLine("Enlist exist: " +
connStrBuilder.ContainsKey("Enlist"));
//returns false
connStrBuilder.ContainsKey("Invalid");
// ShouldSerialize indicates whether or not a specific key
// exists in connection string inherited from DbConnectionStringBuilder.
// returns true if the key is explicitly added the user otherwise false;
// this will return false as this key doesn't exists.
connStrBuilder.ShouldSerialize("user");
// returns false because this key is nott added by user explicitly.
connStrBuilder.ShouldSerialize("Enlist");
// IsFixedSize [read-only property]
Console.WriteLine("Connection String is fixed size only: "
+ connStrBuilder.IsFixedSize);
Console.WriteLine("Key/Value Pair Count: " + connStrBuilder.Count);
//adding a new key which is not supported by the provider
//is not allowed.
try
{
//this will throw an exception.
connStrBuilder.Add("NewKey", "newValue");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("Key/Value Pair Count: " + connStrBuilder.Count);
//modifying a existing key is allowed.
connStrBuilder.Add("Enlist", false);
Console.WriteLine("Key/Value Pair Count: " + connStrBuilder.Count);
// Get all the keys and values supported by the provider.
ICollection keyCollection = connStrBuilder.Keys;
ICollection valueCollection = connStrBuilder.Values;
IEnumerator keys = keyCollection.GetEnumerator();
IEnumerator values = valueCollection.GetEnumerator();
while (keys.MoveNext())
{
values.MoveNext();
Console.WriteLine("Key: {0} Value: {1} \n"
,keys.Current ,values.Current);
}
}
}
Namespace: Oracle.DataAccess.Client
Assembly: Oracle.DataAccess.dll
ODP.NET Version: ODP.NET for .NET Framework 2.0 or ODP.NET for .NET Framework 4
See Also:
OracleConnectionStringBuilder members are listed in the following tables.
OracleConnectionStringBuilder Constructors
OracleConnectionStringBuilder constructors are listed in Table 7-5.
Table 7-5 OracleConnectionStringBuilder Constructors
| Constructor | Description |
|---|---|
|
Instantiates a new instance of |
OracleConnectionStringBuilder Public Properties
OracleConnectionStringBuilder instance properties are listed in Table 7-6.
Table 7-6 OracleConnectionStringBuilder Public Properties
| Properties | Description |
|---|---|
|
|
Inherited from |
|
Specifies the value corresponding to the |
|
|
|
Inherited from |
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
|
Inherited from |
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Indicates whether or not the Connection String Builder has a fixed size |
|
|
|
Inherited from |
|
Specifies the value associated with the specified attribute |
|
|
Specifies a collection of attributes contained in the Connection String Builder |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value that corresponds to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies a collection of values contained in the Connection String Builder |
OracleConnectionStringBuilder Public Methods
OracleConnectionStringBuilder instance methods are listed in Table 7-7.
Table 7-7 OracleConnectionStringBuilder Public Methods
| Methods | Description |
|---|---|
|
|
Inherited from |
|
Clears the connection string contents |
|
|
Indicates whether or not a specific attribute in the connection string is supported by ODP.NET |
|
|
|
Inherited from |
|
Removes the entry corresponding to the specified attribute from the connection string |
|
|
|
Inherited from |
|
|
Inherited from |
|
Returns the value corresponding to the supplied attribute, as an output parameter |
OracleConnectionStringBuilder constructors instantiate new instances of the OracleConnectionStringBuilder class.
OracleConnectionStringBuilder()
This constructor instantiates a new instance of OracleConnectionStringBuilder class.
OracleConnectionStringBuilder(string)
This constructor instantiates a new instance of the OracleConnectionStringBuilder class with the provided connection string.
See Also:
This constructor instantiates a new instance of the OracleConnectionStringBuilder class.
// C# public OracleConnectionStringBuilder();
The ConnectionString property is empty after the object is created.
See Also:
"Oracle.DataAccess.Client Namespace"This constructor instantiates a new instance of the OracleConnectionStringBuilder class with the provided connection string.
// C#
public OracleConnectionStringBuilder(string connectionString);
connectionString
The connection information.
ArgumentNullException - The connectionString parameter is null.
ArgumentException - The connectionString parameter is invalid.
The ConnectionString property of this instance is set to the supplied connection string.
OracleConnectionStringBuilder public properties are listed in Table 7-8.
Table 7-8 OracleConnectionStringBuilder Public Properties
| Properties | Description |
|---|---|
|
|
Inherited from |
|
Specifies the value corresponding to the |
|
|
|
Inherited from |
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
|
Inherited from |
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Indicates whether or not the Connection String Builder has a fixed size |
|
|
|
Inherited from |
|
Specifies the value associated with the specified attribute |
|
|
Specifies a collection of attributes contained in the Connection String Builder |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value that corresponds to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies the value corresponding to the |
|
|
Specifies a collection of values contained in the Connection String Builder |
See Also:
This property specifies the value corresponding to the Connection Lifetime attribute in the ConnectionString property.
// C#
public int ConnectionLifetime{get; set;}
An int that represents the value of the supplied attribute.
OracleException - The specified value is less than zero.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Connection Timeout attribute in the ConnectionString property.
// C#
public int ConnectionTimeout{get; set;}
An int that represents the value of the supplied attribute.
OracleException - The specified value is less than zero.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Context Connection attribute in the ConnectionString property.
// C#
public bool ContextConnection {get; set;}
A bool that represents the value of the supplied attribute.
This property specifies the value corresponding to the Data Source attribute in the ConnectionString property.
// C#
public string DataSource{get; set;}
A string that represents the value of the supplied attribute.
ArgumentNullException - The specified value is null.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the DBA Privilege attribute in the ConnectionString property.
// C#
public string DBAPrivilege{get; set;}
A string that represents the value of the supplied attribute.
Possible values are SYSDBA or SYSOPER.
ArgumentNullException - The specified value is null.
OracleException - The specified value is invalid.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Decr Pool Size attribute in the ConnectionString property.
// C#
public int DecrPoolSize{get; set;}
An int that represents the value of the supplied attribute.
OracleException - The specified value is less than 1.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Enlist attribute in the ConnectionString property.
// C#
public string Enlist{get; set;};
A string that represents the value of the supplied attribute. Values are case-insensitive. Possible values are: dynamic, true, false, yes, and no.
ArgumentNullException - The specified value is null.
OracleException - The supplied value is not one of following: dynamic, true, false, yes, or no.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the HA Events attribute in the ConnectionString property.
// C#
public bool HAEvents{get; set;}
A bool that represents the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Incr Pool Size attribute in the ConnectionString property.
// C#
public int IncrPoolSize{get; set;}
An int that represents the value of the supplied attribute.
OracleException - The specified value is less than 1.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
Indicates whether or not the Connection String Builder has a fixed size.
// C#
public override bool IsFixedSize{get;}
Returns true if the Connection String Builder has a fixed size; otherwise, returns false.
Attributes cannot be added or removed. They can only be modified for connection strings with a fixed size.
This property specifies the value associated with the specified attribute.
// C#
public override object this[string keyword]{get; set;}
An object value corresponding to the attribute.
ArgumentNullException - The specified attribute is null.
OracleException - The specified attribute is not supported or the specified value is invalid.
This property specifies a collection of attributes contained in the Connection String Builder.
// C#
public override ICollection Keys{get;}
Returns an ICollection that represents the attributes in the Connection String Builder.
This property specifies the value corresponding to the Load Balancing attribute in the ConnectionString property.
// C#
public bool LoadBalancing {get; set;}
A bool that contains the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Max Pool Size attribute in the ConnectionString property.
// C#
public int MaxPoolSize{get; set;}
An int that represents the value of the supplied attribute.
OracleException - The specified value is less than 1.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value that corresponds to the Metadata Pooling attribute in the ConnectionString property.
// C#
public bool MetadataPooling{get; set;};
A bool containing the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Min Pool Size attribute in the ConnectionString property.
// C#
public int MinPoolSize{get; set;}
An int that contains the value of the supplied attribute.
OracleException - The specified value is less than 0.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Password attribute in the ConnectionString property.
// C#
public string Password{get; set;}
A string that contains the value of the supplied attribute.
ArgumentNullException - The specified value is null.
This property specifies the value corresponding to the Persist Security Info attribute in the ConnectionString property.
// C#
public bool PersistSecurityInfo{get; set;}
A bool that represents the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property gets set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Pooling attribute in the ConnectionString property.
// C#
public bool Pooling {get; set;}
A bool that represents the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Proxy Password attribute in the ConnectionString property.
// C#
public string ProxyPassword {get; set;}
A string that represents the value of the supplied attribute.
ArgumentNullException - The specified value is null.
This property specifies the value corresponding to the Proxy User Id attribute in the ConnectionString property.
// C#
public string ProxyUserId {get; set;}
A string that represents the value of the supplied attribute.
ArgumentNullException - The specified value is null.
This property specifies the value corresponding to the Self Tuning attribute in the ConnectionString property.
// C#
public bool SelfTuning {get; set;}
A bool that represents the value of the supplied attribute.
This property specifies the value corresponding to the Statement Cache Purge attribute in the ConnectionString property.
// C#
public bool StatementCachePurge {get; set;}
A bool that represents the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the Statement Cache Size attribute in the ConnectionString property.
// C#
public int StatementCacheSize{get; set;}
An int that represents the value of the supplied attribute.
OracleException - The specified value is less than zero.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies the value corresponding to the User Id attribute in the ConnectionString property.
// C#
public string UserID{get; set;}
A string that represents the value of the supplied attribute.
ArgumentNullException - The specified value is null.
This property specifies the value corresponding to the Validate Connection attribute in the ConnectionString property.
// C#
public bool ValidateConnection{get; set;}
A bool that represents the value of the supplied attribute.
When an OracleConnectionStringBuilder instance is created, this property is set to the default value of the corresponding connection string attribute.
This property specifies a collection of values contained in the Connection String Builder.
// C#
public override ICollection Values{get;}
Returns an ICollection that represents the values in the Connection String Builder.
The order of the values in the ICollection is unspecified, but is the same as the associated attributes in the ICollection returned by the Keys property.
OracleConnectionStringBuilder public methods are listed in Table 7-9.
Table 7-9 OracleConnectionStringBuilder Public Methods
| Methods | Description |
|---|---|
|
|
Inherited from |
|
Clears the connection string contents |
|
|
Indicates whether or not a specific attribute in the connection string is supported by ODP.NET |
|
|
|
Inherited from |
|
Removes the entry corresponding to the specified attribute from the connection string |
|
|
|
Inherited from |
|
|
Inherited from |
|
Returns the value corresponding to the supplied attribute, as an output parameter |
See Also:
This method clears the connection string contents.
// C# public override void Clear();
All key/value pairs are removed from the OracleConnectionStringBuilder object and the ConnectionString property is set to Empty.
This method indicates whether or not a specific attribute in the connection string is supported by ODP.NET.
// C#
public override bool ContainsKey(string keyword);
keyword
The attribute being verified.
Returns true if the specified attribute exists; otherwise, returns false.
ArgumentNullException - The specified attribute is null.
This method indicates if the attribute is part of the provider-supported attributes. It does not indicate if the user added the attribute to the connection string.
This method removes the entry corresponding to the specified attribute from the connection string.
// C#
public override bool Remove(string keyword);
keyword
The attribute that specifies the entry to be removed.
Returns true if the attribute existed in the connection string and the corresponding entry was removed; otherwise, returns false.
ArgumentNullException - The specified attribute is null.
This method returns the value corresponding to the supplied attribute, as an output parameter.
// C# public override bool TryGetValue(string keyword, out object value);
keyword
The attribute for which the value is being retrieved.
value
The value of the supplied attribute.
Sets value to the default value if the attribute is not present in the connection string.
Returns true if the value that corresponds to the attribute has been successfully retrieved; otherwise, returns false. If the attribute is not present in the connection string, returns false and sets the value to null.
ArgumentNullException - The specified attribute is null.
If the function returns false, sets value to null.
If the attribute is not present in the connection string, sets value to the default value.