普通的控制台程序中,能够用如下代码取出数据库连接字符串web
1 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
而在一些web项目中,能够尝试使用以面代码来取出配置文件中的信息数据库
1 Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);