OdbcConnectionStringBuilder コンストラクタ (String)
アセンブリ: System.Data (system.data.dll 内)




次の例では、複数の OdbcConnectionStringBuilder インスタンスを作成し、それぞれの場合について異なる接続文字列をコンストラクタに渡しています。ConnectionString プロパティを取得すると、接続文字列における要素の順序が変わる場合があります。定義済みの "Dsn" や "Driver" 以外のキーは、OdbcConnectionStringBuilder クラスによって小文字に変換されます。
![]() |
---|
この例には、OdbcConnectionStringBuilder と接続文字列がどのように連携するかを示すパスワードが含まれています。アプリケーションでは、Windows 認証の使用をお勧めします。パスワードを使用する必要がある場合は、ハードコーディングされたパスワードをアプリケーションに組み込まないでください。 |
Imports System.Data.Odbc Module Module1 Sub 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 ex As System.ArgumentException Console.WriteLine("Error: " & ex.Message) End Try End Sub Private Sub DumpBuilderContents(ByVal connectString As String) Dim builder As New OdbcConnectionStringBuilder(connectString) Console.WriteLine("=================") Console.WriteLine("Original connectString = " & connectString) Console.WriteLine("builder.ConnectionString = " & builder.ConnectionString) For Each key As String In builder.Keys Console.WriteLine(key & "=" & builder.Item(key).ToString) Next End Sub End Module
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 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OdbcConnectionStringBuilder コンストラクタ

名前 | 説明 |
---|---|
OdbcConnectionStringBuilder () | OdbcConnectionStringBuilder クラスの新しいインスタンスを初期化します。 |
OdbcConnectionStringBuilder (String) | OdbcConnectionStringBuilder クラスの新しいインスタンスを初期化します。引数に渡した接続文字列によって、インスタンスの内部的な接続情報のデータが提供されます。 |

OdbcConnectionStringBuilder コンストラクタ ()
アセンブリ: System.Data (system.data.dll 内)


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- OdbcConnectionStringBuilder コンストラクタのページへのリンク