如何:从 Web.config 文件读取连接字符串
2009-07-27 09:18
387 查看
C#
复制代码
复制代码
connectionStrings 元素是 元素的直接子级,并且是 system.web 元素的对等项。
复制代码
System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot"); System.Configuration.ConnectionStringSettings connString; if (0 < rootWebConfig.ConnectionStrings.ConnectionStrings.Count) { connString = rootWebConfig.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"]; if (null != connString) Console.WriteLine("Northwind connection string = \"{0}\"", connString.ConnectionString); else Console.WriteLine("No Northwind connection string"); }
编译代码
此示例需要:根 Web.config 文件中的 connectionStrings 元素,其中包含名为 NorthwindConnectionString 的连接。该元素可能如下所示:复制代码
connectionStrings 元素是 元素的直接子级,并且是 system.web 元素的对等项。
相关文章推荐
- 如何:从Web.config 文件读取连接字符串
- 从Web.config文件中读取数据库连接的字符串
- 从Web.config文件中读取连接字符串的两种方法
- WebService如何从Web.Config中读取数据库连接字符串
- [导入].NET中使用三层构架如何从DAL层读取web.config中的数据库连接字符串!
- C#中如何读取webconfig.xml里的数据库连接字符串
- 从Web.config 文件读取连接字符串
- NET中使用三层构架如何从DAL层读取web.config中的数据库连接字符串!
- 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
- 如何加密Web.Config中的连接字符串
- 关于如何得到web.config中的数据库连接字符串
- winform .cs 类文件中读取App.config数据连接字符串
- 如何加密Web.Config中的连接字符串
- .net下在Web.Config文件中添加连接字符串
- 如何在web.config文件中配置连接Access数据库?
- 如何加密Web.Config中的连接字符串
- 从Web.Config中读取数据库连接字符串的问题
- cs中读取web.config中的数据库连接字符串(两种)
- 在web.config中如何配置数据库连接字符串,较为安全?
- ASP.NET数据库连接字符串写在config.web配置文件中(1)