OracleConnectionStringBuilder Constructors

Definition

Initializes a new instance of the OracleConnectionStringBuilder class.

Overloads

OracleConnectionStringBuilder()

Initializes a new instance of the OracleConnectionStringBuilder class.

OracleConnectionStringBuilder(String)

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

OracleConnectionStringBuilder()

Initializes a new instance of the OracleConnectionStringBuilder class.

public OracleConnectionStringBuilder ();

See also

Applies to

.NET Framework 4.8.1 og andre versioner
Produkt Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

OracleConnectionStringBuilder(String)

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

public OracleConnectionStringBuilder (string connectionString);

Parameters

connectionString
String

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

Exceptions

Invalid key name within the connection string.

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

Examples

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

Bemærk

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.

// You may need to set a reference to the System.Data.OracleClient
// assembly before you can run this sample.
using System.Data.OracleClient;

class Program
{
    static void Main()
    {
        try
        {
            string connectString = "Server=OracleDemo;UID=Mary;Pwd=*****";
            Console.WriteLine("Original: " + connectString);
            OracleConnectionStringBuilder builder =
                new OracleConnectionStringBuilder(connectString);
            Console.WriteLine("Modified: " + builder.ConnectionString);
            foreach (string key in builder.Keys)
                Console.WriteLine(key + "=" + builder[key].ToString());
            Console.WriteLine("Press any key to finish.");
            Console.ReadLine();
        }
        catch (System.Collections.Generic.KeyNotFoundException ex)
        {
            Console.WriteLine("KeyNotFoundException: " + ex.Message);
        }
        catch (System.FormatException ex)
        {
            Console.WriteLine("Format exception: " + ex.Message);
        }
    }
}

Remarks

The OracleConnectionStringBuilder 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 different from the default value for the item.

See also

Applies to

.NET Framework 4.8.1 og andre versioner
Produkt Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1