0

我创建了一个指向我的 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=&quot;data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 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=&quot;data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

问题是我的 .edmx 文件不会读取连接字符串:

我收到一个错误:对象引用未设置为对象的实例?

 string constrng = ConfigurationManager.ConnectionStrings["NorthwindEntities"].ToString();
4

0 回答 0