OdbcConnectionStringBuilder.Keys Property
Gets an ICollection that contains the keys in the OdbcConnectionStringBuilder.
Assembly: System.Data (in System.Data.dll)
Property Value
Type: System.Collections.ICollectionAn ICollection that contains the keys in the OdbcConnectionStringBuilder.
Implements
IDictionary.KeysThe order of the values in the ICollection is the same order as the associated values in the ICollection returned by the Values property.
The following console application example creates a new OdbcConnectionStringBuilder. The code loops through the ICollection returned by the Keys property displaying the key/value pairs.
Note
|
|---|
|
This example includes a password to demonstrate how OdbcConnectionStringBuilder 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. |
using System.Data.Odbc; class Program { static void Main() { try { // Build an empty instance, just to see // the contents of the keys. DumpBuilderContents(""); // Create a SQL Server connection string. DumpBuilderContents("Driver={SQL Server};Server=(local);Database=AdventureWorks;Uid=ab;Pwd=pass@word1"); // Create an Access connection string. DumpBuilderContents(@"Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\info.mdb;Exclusive=1;Uid=admin;Pwd=pass@word1"); // Create an Oracle connection string. DumpBuilderContents("Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Admin;Pwd=pass@word1;"); // Create a Sybase connection string. DumpBuilderContents("Driver={SYBASE ASE ODBC Driver};Srvr=SomeServer;Uid=admin;Pwd=pass@word1"); Console.WriteLine("Press any key to finish."); Console.ReadLine(); } catch (System.ArgumentException ex) { Console.WriteLine("Error: " + ex.Message); } } private static void DumpBuilderContents(string connectString) { OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder(connectString); Console.WriteLine("================="); Console.WriteLine("Original connectString = " + connectString); Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString); foreach (string key in builder.Keys) { Console.WriteLine(key + "=" + builder[key].ToString()); } } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note