當前位置: 首頁>>代碼示例>>C#>>正文


C# ConnectionStringSettings類代碼示例

本文整理匯總了C#中System.Configuration.ConnectionStringSettings的典型用法代碼示例。如果您正苦於以下問題:C# ConnectionStringSettings類的具體用法?C# ConnectionStringSettings怎麽用?C# ConnectionStringSettings使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectionStringSettings類屬於System.Configuration命名空間,在下文中一共展示了ConnectionStringSettings類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DisplayConnectionStrings

//引入命名空間
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Configuration;
using System.Collections;
using System.Text;

namespace ConfigurationStringSettings
{

    class ConfigurationStringSettings
    {

        static void DisplayConnectionStrings()
        {
            // Set the path of the config file.
            // Make sure that you have a Web site on the
            // same server called TestConfig. 
            string configPath = "/TestConfig";

            // Get the Web application configuration object.
            Configuration config =
              WebConfigurationManager.OpenWebConfiguration(configPath);

            // Get the conectionStrings section.
            ConnectionStringsSection csSection =
                config.ConnectionStrings;

            Console.WriteLine("Display configuration strings.");

            for (int i = 0; i <
                ConfigurationManager.ConnectionStrings.Count; i++)
            {
                ConnectionStringSettings cs =
                    csSection.ConnectionStrings[i];

                Console.WriteLine("  Connection String: \"{0}\"",
                    cs.ConnectionString);

                Console.WriteLine("#{0}", i);
                Console.WriteLine("  Name: {0}", cs.Name);

                Console.WriteLine("  Provider Name: {0}",
                    cs.ProviderName);
            }
        }

        static void Main(string[] args)
        {
            try
            {   // Display connection strings.
                DisplayConnectionStrings();
            }
            catch (Exception e)
            {
                // Unknown error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.WriteLine("Enter any key to exit.");
            Console.ReadLine();
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Configuration,代碼行數:66,代碼來源:ConnectionStringSettings


注:本文中的System.Configuration.ConnectionStringSettings類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。