OracleConnectionStringBuilder 类

定义

注意

OracleConnectionStringBuilder has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260

为创建和管理由 OracleConnection 类使用的连接字符串的内容提供了一种简单方法。Provides a simple way to create and manage the contents of connection strings used by the OracleConnection class.

public ref class OracleConnectionStringBuilder sealed : System::Data::Common::DbConnectionStringBuilder
[System.ComponentModel.TypeConverter(typeof(System.Data.OracleClient.OracleConnectionStringBuilder/OracleConnectionStringBuilderConverter))]
public sealed class OracleConnectionStringBuilder : System.Data.Common.DbConnectionStringBuilder
[System.ComponentModel.TypeConverter(typeof(System.Data.OracleClient.OracleConnectionStringBuilder/OracleConnectionStringBuilderConverter))]
[System.Obsolete("OracleConnectionStringBuilder has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260", false)]
public sealed class OracleConnectionStringBuilder : System.Data.Common.DbConnectionStringBuilder
[<System.ComponentModel.TypeConverter(typeof(System.Data.OracleClient.OracleConnectionStringBuilder/OracleConnectionStringBuilderConverter))>]
type OracleConnectionStringBuilder = class
    inherit DbConnectionStringBuilder
[<System.ComponentModel.TypeConverter(typeof(System.Data.OracleClient.OracleConnectionStringBuilder/OracleConnectionStringBuilderConverter))>]
[<System.Obsolete("OracleConnectionStringBuilder has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260", false)>]
type OracleConnectionStringBuilder = class
    inherit DbConnectionStringBuilder
Public NotInheritable Class OracleConnectionStringBuilder
Inherits DbConnectionStringBuilder
继承
OracleConnectionStringBuilder
属性

示例

下面的控制台应用程序将生成 Oracle 数据库的连接字符串。The following console application builds connection strings for an Oracle database. 此代码使用 OracleConnectionStringBuilder 类创建连接字符串,然后将 ConnectionString 该实例的属性传递 OracleConnectionStringBuilder 给 connection 类的构造函数。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.

备注

该示例包括一个密码以演示 OracleConnectionStringBuilder 如何使用连接字符串。This example includes a password to demonstrate how OracleConnectionStringBuilder works with connection strings. 在您的应用程序中,建议使用 Windows 身份验证。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()
    {
        // Create a new OracleConnectionStringBuilder and
        // initialize it with a few name/value pairs.
        OracleConnectionStringBuilder builder =
            new OracleConnectionStringBuilder(GetConnectionString());

        // Note that the input connection string used the
        // Server key, but the new connection string uses
        // the well-known Data Source key instead.
        Console.WriteLine(builder.ConnectionString);

        // Pass the OracleConnectionStringBuilder an existing
        // connection string, and you can retrieve and
        // modify any of the elements.
        builder.ConnectionString = "server=OracleDemo;user id=maryc;" +
            "password=pass@word1";

        // Now that the connection string has been parsed,
        // you can work with individual items.
        Console.WriteLine(builder.Password);
        builder.Password = "newPassword";
        builder.PersistSecurityInfo = true;

        // You can refer to connection keys using strings,
        // as well. When you use this technique (the default
        // Item property in Visual Basic, or the indexer in C#),
        // you can specify any synonym for the connection string key
        // name.
        builder["Server"] = ".";
        builder["Load Balance Timeout"] = 1000;
        builder["Integrated Security"] = true;
        Console.WriteLine(builder.ConnectionString);

        Console.WriteLine("Press Enter to finish.");
        Console.ReadLine();
    }

    private static string GetConnectionString()
    {
        // To avoid storing the connection string in your code,
        // you can retrieve it from a configuration file.
        return "Server=OracleDemo;Integrated Security=true";
    }
}
' You may need to set a reference to the System.Data.OracleClient
' assembly before running this example.
Imports System.Data.OracleClient

Module Module1
  Sub Main()
    ' Create a new OracleConnectionStringBuilder and
    ' initialize it with a few name/value pairs.
    Dim builder As New OracleConnectionStringBuilder(GetConnectionString())

    ' Note that the input connection string used the 
    ' Server key, but the new connection string uses
    ' the well-known Data Source key instead.
    Console.WriteLine(builder.ConnectionString)

    ' Pass the OracleConnectionStringBuilder an existing 
    ' connection string, and you can retrieve and
    ' modify any of the elements.
    builder.ConnectionString = _
        "server=OracleDemo;user id=Mary;" & _
        "password=*****"
    ' Now that the connection string has been parsed,
    ' you can work with individual items.
    Console.WriteLine(builder.Password)
    builder.Password = "newPassword"
    builder.PersistSecurityInfo = True

    ' You can refer to connection keys using strings, 
    ' as well. When you use this technique (the default
    ' Item property in Visual Basic, or the indexer in C#),
    ' you can specify any synonym for the connection string key
    ' name.
    builder("Server") = "NewDemo"
    builder("Load Balance Timeout") = 1000

    ' The Item property is the default for the class, 
    ' and setting the Item property adds the value to the 
    ' dictionary, if necessary. 
    builder.Item("Integrated Security") = True
    Console.WriteLine(builder.ConnectionString)

    Console.WriteLine("Press Enter to finish.")
    Console.ReadLine()
  End Sub

  Private Function GetConnectionString() As String
    ' To avoid storing the connection string in your code,
    ' you can retrieve it from a configuration file. 
    Return "Server=OracleDemo;Integrated Security=True;" & _
      "Unicode=True"
  End Function

End Module

注解

此类型已弃用,并将在 .NET Framework 的未来版本中删除。This type is deprecated and will be removed in a future version of the .NET Framework. 有关详细信息,请参阅 Oracle 和 ADO.NETFor more information, see Oracle and ADO.NET.

连接字符串生成器允许开发人员以编程方式创建语法正确的连接字符串,并使用类的属性和方法来分析和重新生成现有的连接字符串。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. 连接字符串生成器提供了与 Oracle 允许的已知键/值对相对应的强类型属性。The connection string builder provides strongly typed properties corresponding to the known key/value pairs allowed by Oracle. OracleConnectionStringBuilder 类实现 ICustomTypeDescriptor 接口。The OracleConnectionStringBuilder class implements the ICustomTypeDescriptor interface. 这意味着该类在设计时适用于 Visual Studio .NET 设计器。This means that the class works with Visual Studio .NET designers at design time. 当开发人员使用设计器在 Visual Studio .NET 中生成强类型化 数据集 和强类型连接时,强类型连接字符串生成器类将显示与其类型关联的属性,并且还将具有可映射已知密钥的公共值的转换器。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.

需要在应用程序中创建连接字符串的开发人员可以使用 OracleConnectionStringBuilder 类生成和修改连接字符串。Developers needing to create connection strings as part of applications can use the OracleConnectionStringBuilder class to build and modify connection strings. OracleConnectionStringBuilder类还可以轻松管理存储在应用程序配置文件中的连接字符串。The OracleConnectionStringBuilder class also makes it easy to manage connection strings stored in an application configuration file.

OracleConnectionStringBuilder 对键/值对的有效性进行检查。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. OracleConnectionStringBuilder类维护一个固定的同义词集合,并在需要时执行所需的转换,以将同义词转换为相应的已知键名。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. 例如,使用 Item[] 属性检索值时,可以指定一个字符串,该字符串包含所需的键的任何同义词。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. 有关可接受同义词的完整列表,请参见 Item[] 属性。See the Item[] property for a full list of acceptable synonyms.

OracleConnectionStringBuilder句柄尝试插入恶意条目。The OracleConnectionStringBuilder handles attempts to insert malicious entries. 例如,下面的代码使用 Item[] 索引器 (的默认属性(在 c # 中) ) 正确地转义嵌套的键/值对。For example, the following code, using the default Item[] property (the indexer, in C#) correctly escapes the nested key/value pair.

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)  
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);  

结果是以下连接字符串,通过将用户 ID 值括在引号中,以安全的方式处理无效值: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"  

构造函数

OracleConnectionStringBuilder()

初始化 OracleConnectionStringBuilder 类的新实例。Initializes a new instance of the OracleConnectionStringBuilder class.

OracleConnectionStringBuilder(String)

初始化 OracleConnectionStringBuilder 类的新实例。Initializes a new instance of the OracleConnectionStringBuilder class. 所提供的连接字符串为实例的内部连接信息提供数据。The provided connection string provides the data for the instance's internal connection information.

属性

BrowsableConnectionString

获取或设置一个值,该值指示 ConnectionString 属性是否在 Visual Studio 设计器中可见。Gets or sets a value that indicates whether the ConnectionString property is visible in Visual Studio designers.

(继承自 DbConnectionStringBuilder)
ConnectionString

获取或设置与 DbConnectionStringBuilder 相关联的连接字符串。Gets or sets the connection string associated with the DbConnectionStringBuilder.

(继承自 DbConnectionStringBuilder)
Count

获取属性 ConnectionString 中包含的键的当前数目。Gets the current number of keys that are contained within the ConnectionString property.

(继承自 DbConnectionStringBuilder)
DataSource

获取或设置要连接到的 Oracle 数据源的名称。Gets or sets the name of the Oracle data source to connect to.

Enlist

获取或设置一个值,该值指示池程序是否在创建线程的当前事务上下文中自动登记连接。Gets or sets a value that indicates whether the pooler automatically enlists the connection in the creation thread's current transaction context.

IntegratedSecurity

获取或设置一个值,该值指示连接中是否指定了“User ID”和“Password”(当为 false 时),或者是否使用当前的 Windows 帐户凭据进行身份验证(当为 true 时)。Gets or sets a value that indicates whether "User ID" and "Password" are specified in the connection (when false) or whether the current Windows account credentials are used for authentication (when true).

IsFixedSize

获取一个值,该值指示 OracleConnectionStringBuilder 是否具有固定大小。Gets a value that indicates whether the OracleConnectionStringBuilder has a fixed size.

IsReadOnly

获取一个值,该值指示 DbConnectionStringBuilder 是否为只读。Gets a value that indicates whether the DbConnectionStringBuilder is read-only.

(继承自 DbConnectionStringBuilder)
Item[String]

获取或设置与指定的键关联的值。Gets or sets the value associated with the specified key. 在 C# 中,此属性为索引器。In C#, this property is the indexer.

Keys

获取包含 ICollection 中的键的 OracleConnectionStringBuilderGets an ICollection that contains the keys in the OracleConnectionStringBuilder.

LoadBalanceTimeout

获取或设置连接被移除之前在连接池中的最短存活时间(以秒为单位)。Gets or sets the minimum time, in seconds, for the connection to live in the connection pool before it is removed.

MaxPoolSize

获取或设置针对此特定连接字符串连接池中所允许的最大连接数。Gets or sets the maximum number of connections allowed in the connection pool for this specific connection string.

MinPoolSize

获取或设置针对此特定连接字符串连接池中所允许的最小连接数。Gets or sets the minimum number of connections allowed in the connection pool for this specific connection string.

OmitOracleConnectionName

获取或设置启用 Oracle 早期版本(8.1.7.4.1 以前的版本)中的事务回滚的标志。Gets or sets the flag that enables transaction rollbacks on earlier versions of Oracle (prior to 8.1.7.4.1).

Password

获取或设置 Oracle 帐户的密码。Gets or sets the password for the Oracle account.

PersistSecurityInfo

获取或设置一个布尔值,该值指示如果连接是打开的或者一直处于打开状态,那么安全敏感信息(如密码)是否将不作为连接的一部分返回。Gets or sets a Boolean value that indicates if security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state.

Pooling

获取或设置一个布尔值,该值指示连接是否加入池中,或者在每次请求连接时,每个连接是否被显式打开。Gets or sets a Boolean value that indicates whether the connection will be pooled, or whether each connection will be explicitly opened every time that the connection is requested.

Unicode

获取或设置一个布尔值,该值指示客户端是否支持较高版本的 Oracle 客户端中可用的 Unicode 功能,或者该客户端是否可以识别非 Unicode。Gets or sets a Boolean value that indicates if the client supports the Unicode functionality available in later Oracle clients, or if it is non-Unicode aware.

UserID

获取或设置在连接到 Oracle 时要使用的用户 ID。Gets or sets the user ID to be used when connecting to Oracle.

Values

获取一个包含 ICollection 中的值的 OracleConnectionStringBuilderGets an ICollection that contains the values in the OracleConnectionStringBuilder.

方法

Add(String, Object)

将带有指定键和值的条目添加到 DbConnectionStringBuilder 中。Adds an entry with the specified key and value into the DbConnectionStringBuilder.

(继承自 DbConnectionStringBuilder)
Clear()

清除 OracleConnectionStringBuilder 实例的内容。Clears the contents of the OracleConnectionStringBuilder instance.

ClearPropertyDescriptors()

清除关联的 DbConnectionStringBuilder 上的 PropertyDescriptor 对象集合。Clears the collection of PropertyDescriptor objects on the associated DbConnectionStringBuilder.

(继承自 DbConnectionStringBuilder)
ContainsKey(String)

确定 OracleConnectionStringBuilder 是否包含特定键。Determines whether the OracleConnectionStringBuilder contains a specific key.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
EquivalentTo(DbConnectionStringBuilder)

将此 DbConnectionStringBuilder 对象中的连接信息与提供的对象中的连接信息进行比较。Compares the connection information in this DbConnectionStringBuilder object with the connection information in the supplied object.

(继承自 DbConnectionStringBuilder)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetProperties(Hashtable)

使用有关此 DbConnectionStringBuilder 的所有属性的信息,填充提供的 HashtableFills a supplied Hashtable with information about all the properties of this DbConnectionStringBuilder.

(继承自 DbConnectionStringBuilder)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(String)

OracleConnectionStringBuilder 实例中移除具有指定的键的项。Removes the entry with the specified key from the OracleConnectionStringBuilder instance.

ShouldSerialize(String)

指示此 OracleConnectionStringBuilder 实例中是否存在指定的键。Indicates whether the specified key exists in this OracleConnectionStringBuilder instance.

ToString()

返回与此 DbConnectionStringBuilder 关联的连接字符串。Returns the connection string associated with this DbConnectionStringBuilder.

(继承自 DbConnectionStringBuilder)
TryGetValue(String, Object)

从此 OracleConnectionStringBuilder 中检索与提供的键相对应的值。Retrieves a value corresponding to the supplied key from this OracleConnectionStringBuilder.

显式接口实现

ICollection.CopyTo(Array, Int32)

从特定的 ICollection 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the ICollection to an Array, starting at a particular Array index.

(继承自 DbConnectionStringBuilder)
ICollection.IsSynchronized

获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

(继承自 DbConnectionStringBuilder)
ICollection.SyncRoot

获取可用于同步对 ICollection 的访问的对象。Gets an object that can be used to synchronize access to the ICollection.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetAttributes()

返回此组件实例的自定义属性的集合。Returns a collection of custom attributes for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetClassName()

返回此组件实例的类名称。Returns the class name of this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetComponentName()

返回某个组件的此实例的名称。Returns the name of this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetConverter()

返回此组件实例的类型转换器。Returns a type converter for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetDefaultEvent()

返回某个组件的此实例的默认事件。Returns the default event for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetDefaultProperty()

返回此组件实例的默认属性。Returns the default property for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetEditor(Type)

返回此组件实例的指定类型的编辑器。Returns an editor of the specified type for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetEvents()

返回此组件实例的事件。Returns the events for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetEvents(Attribute[])

使用指定的属性数组作为筛选器,返回此组件实例的事件。Returns the events for this instance of a component using the specified attribute array as a filter.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetProperties()

返回此组件实例的属性。Returns the properties for this instance of a component.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetProperties(Attribute[])

使用特性数组作为筛选器,返回此组件实例的属性。Returns the properties for this instance of a component using the attribute array as a filter.

(继承自 DbConnectionStringBuilder)
ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor)

返回一个对象,该对象包含指定的属性描述符所描述的属性。Returns an object that contains the property described by the specified property descriptor.

(继承自 DbConnectionStringBuilder)
IDictionary.Add(Object, Object)

IDictionary 对象中添加一个带有所提供的键和值的元素。Adds an element with the provided key and value to the IDictionary object.

(继承自 DbConnectionStringBuilder)
IDictionary.Contains(Object)

确定 IDictionary 对象是否包含具有指定键的元素。Determines whether the IDictionary object contains an element with the specified key.

(继承自 DbConnectionStringBuilder)
IDictionary.GetEnumerator()

返回 IDictionary 对象的 IDictionaryEnumerator 对象。Returns an IDictionaryEnumerator object for the IDictionary object.

(继承自 DbConnectionStringBuilder)
IDictionary.IsFixedSize

获取一个值,该值指示 IDictionary 对象是否具有固定大小。Gets a value indicating whether the IDictionary object has a fixed size.

(继承自 DbConnectionStringBuilder)
IDictionary.IsReadOnly

获取一个值,该值指示 IDictionary 是否为只读。Gets a value indicating whether the IDictionary is read-only.

(继承自 DbConnectionStringBuilder)
IDictionary.Item[Object]

获取或设置具有指定键的元素。Gets or sets the element with the specified key.

(继承自 DbConnectionStringBuilder)
IDictionary.Remove(Object)

IDictionary 对象中移除具有指定键的元素。Removes the element with the specified key from the IDictionary object.

(继承自 DbConnectionStringBuilder)
IEnumerable.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

(继承自 DbConnectionStringBuilder)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于