Cof*_*ode 29 .net c# .net-4.0 entity-framework-4
我想从app.config文件中获取连接字符串.
connectionString = System.Configuration.ConfigurationSettings.AppSettings["DBEntities"];
但它不起作用.它是空的.
我无法访问,System.Configuration.ConfigurationManager因为它是.net 4.
如何从中获取我的连接字符串app.config?
谢谢
sh_*_*alh 76
使用
string connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
Run Code Online (Sandbox Code Playgroud)
确保System.configuration在项目中添加引用.
在.net 4中你必须使用:
ConfigurationManager.ConnectionStrings["name of connection string in web.config"]
Run Code Online (Sandbox Code Playgroud)