从配置文件中取出数据库链接字符串的技巧

普通的控制台程序中,可以用以下代码取出数据库链接字符串

1 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

而在一些web项目中,可以尝试使用以面代码来取出配置文件中的信息

1 Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);

 

posted @ 2016-05-23 16:07  huhu583  阅读(623)  评论(0编辑  收藏  举报