WebConfigurationManager.ConnectionStrings プロパティ
アセンブリ: System.Web (system.web.dll 内)

public: static property ConnectionStringSettingsCollection^ ConnectionStrings { ConnectionStringSettingsCollection^ get (); }
現在の Web アプリケーションの既定の構成の ConnectionStringsSection オブジェクトの内容を格納している ConnectionStringSettingsCollection オブジェクト。


ConnectionStrings プロパティを使用して構成情報にアクセスする方法を次のコード例に示します。
' Show the use of ConnectionStrings. ' If called from within a client application, ' the GetWebApplicationSection(string) gets the default section ' from the machine.config. ' If called from within a Web aplication it gets the ' section from the configuration file located at the ' application current level. Shared Sub GetConnectionStrings() ' Get the connectionStrings key,value pairs collection. Dim connectionStrings As ConnectionStringSettingsCollection = _ WebConfigurationManager.ConnectionStrings ' Get the collection enumerator. Dim connectionStringsEnum As IEnumerator = _ connectionStrings.GetEnumerator() ' Loop through the collection and ' display the connectionStrings key, value pairs. Dim i As Integer = 0 Console.WriteLine("[Display connectionStrings]") While connectionStringsEnum.MoveNext() Dim name As String = connectionStrings(i).Name Console.WriteLine("Name: {0} Value: {1}", _ name, connectionStrings(name)) i += 1 End While Console.WriteLine() End Sub 'GetConnectionStrings
// Show the use of ConnectionStrings. // If called from within a client application, // the GetWebApplicationSection(string) gets the default section // from the machine.config. // If called from within a Web aplication it gets the // section from the configuration file located at the // application current level. static void GetConnectionStrings() { // Get the connectionStrings key,value pairs collection. ConnectionStringSettingsCollection connectionStrings = WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection; // Get the collection enumerator. IEnumerator connectionStringsEnum = connectionStrings.GetEnumerator(); // Loop through the collection and // display the connectionStrings key, value pairs. int i = 0; Console.WriteLine("[Display connectionStrings]"); while (connectionStringsEnum.MoveNext()) { string name = connectionStrings[i].Name; Console.WriteLine("Name: {0} Value: {1}", name, connectionStrings[name]); i += 1; } Console.WriteLine(); }

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


- WebConfigurationManager.ConnectionStrings プロパティのページへのリンク