我创建了一个指向web.config的链接,该链接被定义为在解决方案级别定义的中央配置文件。所以我遇到麻烦的项目包含对这个配置文件的引用:
的web.config:
<configuration>
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/NWind.csdl|res://*/NWind.ssdl|res://*/NWind.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration
Also I created a .edmx file and the connectionstring is like:
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="NorthwindEntities" connectionString="metadata=res://*/NWind.csdl|res://*/NWind.ssdl|res://*/NWind.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
问题是我的.edmx文件不会读取连接字符串:
我收到错误: 对象引用未设置为对象的实例?
string constrng = ConfigurationManager.ConnectionStrings["NorthwindEntities"].ToString();