本文整理汇总了C#中System.Configuration.ConnectionStringsSection类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionStringsSection类的具体用法?C# ConnectionStringsSection怎么用?C# ConnectionStringsSection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionStringsSection类属于System.Configuration命名空间,在下文中一共展示了ConnectionStringsSection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectionStrings
// 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);
}