本文整理匯總了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();
}
}
}