ConnectionStringsSection クラス
アセンブリ: System.Configuration (system.configuration.dll 内)
構文
解説ConnectionStringsSection クラスを使用すると、構成ファイルの connectionStrings セクションをプログラムから変更できます。接続文字列は、ConnectionStringSettingsadd 構成要素の ConnectionStringSettingsCollection として提供されます。
使用例ConnectionStringsSection を使用する方法の例を次に示します。
' Create a connectionn string element and add it to ' the connection strings section. Shared Sub New() ' Get the application configuration file. Dim config _ As System.Configuration.Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) ' Get the current connection strings count. Dim connStrCnt As Integer = _ ConfigurationManager.ConnectionStrings.Count ' Create the connection string name. Dim csName As String = "ConnStr" + connStrCnt.ToString() ' Create a connection string element and ' save it to the configuration file. ' Create a connection string element. Dim csSettings _ As New ConnectionStringSettings( _ csName, _ "LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" + _ "Initial Catalog=aspnetdb", "System.Data.SqlClient") ' Get the connection strings section. Dim csSection _ As ConnectionStringsSection = _ config.ConnectionStrings ' Add the new element. csSection.ConnectionStrings.Add(csSettings) ' Save the configuration file. config.Save(ConfigurationSaveMode.Modified) End Sub 'New
// Create a connectionn string element and add it to // the connection strings section. static ConnectionStrings() { // Get the application configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); // Get the current connection strings count. int connStrCnt = ConfigurationManager.ConnectionStrings.Count; // Create the connection string name. string csName = "ConnStr" + connStrCnt.ToString(); // Create a connection string element and // save it to the configuration file. // Create a connection string element. ConnectionStringSettings csSettings = new ConnectionStringSettings(csName, "LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" + "Initial Catalog=aspnetdb", "System.Data.SqlClient"); // Get the connection strings section. ConnectionStringsSection csSection = config.ConnectionStrings; // Add the new element. csSection.ConnectionStrings.Add(csSettings); // Save the configuration file. config.Save(ConfigurationSaveMode.Modified); }
継承階層System.Configuration.ConfigurationElement
System.Configuration.ConfigurationSection
System.Configuration.ConnectionStringsSection
スレッド セーフ
プラットフォーム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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照ConnectionStringsSection コンストラクタ
アセンブリ: System.Configuration (system.configuration.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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照ConnectionStringsSection プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| ConnectionStrings | ConnectionStringSettings オブジェクトの ConnectionStringSettingsCollection コレクションを取得します。 |
| ElementInformation | ConfigurationElement オブジェクトのカスタマイズできない情報と機能を格納する ElementInformation オブジェクトを取得します。 ( ConfigurationElement から継承されます。) |
| LockAllAttributesExcept | ロックされている属性のコレクションを取得します。 ( ConfigurationElement から継承されます。) |
| LockAllElementsExcept | ロックされている要素のコレクションを取得します。 ( ConfigurationElement から継承されます。) |
| LockAttributes | ロックされている属性のコレクションを取得します。 ( ConfigurationElement から継承されます。) |
| LockElements | ロックされている要素のコレクションを取得します。 ( ConfigurationElement から継承されます。) |
| LockItem | 要素がロックされているかどうかを示す値を取得または設定します。 ( ConfigurationElement から継承されます。) |
| SectionInformation | ConfigurationSection オブジェクトのカスタマイズできない情報と機能を格納する SectionInformation オブジェクトを取得します。 ( ConfigurationSection から継承されます。) |
参照ConnectionStringsSection メソッド
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 現在の ConfigurationElement インスタンスを、指定したオブジェクトと比較します。 ( ConfigurationElement から継承されます。) |
| GetHashCode | 現在の ConfigurationElement インスタンスを表す一意の値を取得します。 ( ConfigurationElement から継承されます。) |
| GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
| IsReadOnly | ConfigurationElement オブジェクトが読み取り専用かどうかを示す値を取得します。 ( ConfigurationElement から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照ConnectionStringsSection メンバ
接続文字列に関する構成ファイル セクションにプログラムからアクセスできるようにします。
ConnectionStringsSection データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| ConnectionStrings | ConnectionStringSettings オブジェクトの ConnectionStringSettingsCollection コレクションを取得します。 |
| ElementInformation | ConfigurationElement オブジェクトのカスタマイズできない情報と機能を格納する ElementInformation オブジェクトを取得します。 (ConfigurationElement から継承されます。) |
| LockAllAttributesExcept | ロックされている属性のコレクションを取得します。(ConfigurationElement から継承されます。) |
| LockAllElementsExcept | ロックされている要素のコレクションを取得します。(ConfigurationElement から継承されます。) |
| LockAttributes | ロックされている属性のコレクションを取得します。 (ConfigurationElement から継承されます。) |
| LockElements | ロックされている要素のコレクションを取得します。(ConfigurationElement から継承されます。) |
| LockItem | 要素がロックされているかどうかを示す値を取得または設定します。(ConfigurationElement から継承されます。) |
| SectionInformation | ConfigurationSection オブジェクトのカスタマイズできない情報と機能を格納する SectionInformation オブジェクトを取得します。 (ConfigurationSection から継承されます。) |
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 現在の ConfigurationElement インスタンスを、指定したオブジェクトと比較します。 (ConfigurationElement から継承されます。) |
| GetHashCode | 現在の ConfigurationElement インスタンスを表す一意の値を取得します。 (ConfigurationElement から継承されます。) |
| GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
| IsReadOnly | ConfigurationElement オブジェクトが読み取り専用かどうかを示す値を取得します。 (ConfigurationElement から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照- ConnectionStringsSectionのページへのリンク