没有名为“”的连接字符串;NorthwindConnection”;可以在应用程序配置文件中找到
本文关键字:应用程序 配置文件 NorthwindConnection 连接 字符串 | 更新日期: 2023-09-27 18:20:01
我有两个项目:控制台应用程序和dll。在dll中,我正在使用EntityFramework。我有这个app.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="NorthwindConnection" connectionString="Data Source=ВЛАДИСЛАВ-ПК'SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
我正在从控制台应用程序调用EntityFramework,但我收到以下错误消息:"在应用程序配置文件中找不到名为"NorthwindConnection"的连接字符串。".
这是控制台app.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
将以下标记从.dll配置文件复制到控制台项目app.config
:
<connectionStrings>
<add name="NorthwindConnection" connectionString="Data Source=ВЛАДИСЛАВ-ПК'SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa;" providerName="System.Data.SqlClient" />
</connectionStrings>
因此,控制台项目中的app.config
将是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="NorthwindConnection" connectionString="Data Source=ВЛАДИСЛАВ-ПК'SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>