OracleConnectionStringBuilder 构造函数
定义
初始化 OracleConnectionStringBuilder 类的新实例。Initializes a new instance of the OracleConnectionStringBuilder class.
重载
| 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. |
OracleConnectionStringBuilder()
初始化 OracleConnectionStringBuilder 类的新实例。Initializes a new instance of the OracleConnectionStringBuilder class.
public:
OracleConnectionStringBuilder();
public OracleConnectionStringBuilder ();
Public Sub New ()
适用于
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.
public:
OracleConnectionStringBuilder(System::String ^ connectionString);
public OracleConnectionStringBuilder (string connectionString);
new System.Data.OracleClient.OracleConnectionStringBuilder : string -> System.Data.OracleClient.OracleConnectionStringBuilder
Public Sub New (connectionString As String)
参数
- connectionString
- String
对象内部连接信息的基础。The basis for the object's internal connection information. 分析为名称/值对。Parsed into name/value pairs. 无效的键名将引发 KeyNotFoundException。Invalid key names raise a KeyNotFoundException.
例外
连接字符串中包含无效的键名。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).
示例
下面的示例在对象的构造函数中提供了一个简单的连接字符串 OracleConnectionStringBuilder ,然后循环访问该对象中的所有键/值对。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. 另请注意,OracleConnectionStringBuilder 类会转换已知键的同义词,使其与已知名称一致。Also note that the OracleConnectionStringBuilder class converts synonyms for the well-known keys so that they are consistent with the well-known names.
备注
该示例包括一个密码以演示 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()
{
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);
}
}
}
' 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()
Try
Dim connectString As String = "Server=OracleDemo;UID=Mary;Pwd=*****"
Console.WriteLine("Original: " & connectString)
Dim builder As New OracleConnectionStringBuilder(connectString)
Console.WriteLine("Modified: " & builder.ConnectionString)
For Each key As String In builder.Keys
Console.WriteLine(key & "=" & builder.Item(key).ToString)
Next
Console.WriteLine("Press any key to finish.")
Console.ReadLine()
Catch ex As System.Collections.Generic.KeyNotFoundException
Console.WriteLine("KeyNotFoundException: " & ex.Message)
Catch ex As System.FormatException
Console.WriteLine("Format exception: " & ex.Message)
End Try
End Sub
End Module
注解
OracleConnectionStringBuilder 类提供键/值对的固定内部集合。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. ConnectionString检索对象的属性时,字符串只包含值与项的默认值不同的键/值对。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.