我在我的WCF服务项目中创建了一个ADO.NET对象,但是当我试图连接它时,我得到了以下错误:
在应用程序配置文件中找不到名为“FileEntities”的连接字符串。
这是我的代码:
public File GetFile() { using (FileEntities ctx = new FileEntities()) { File aFile = (from f in ctx.Files where f.ID == 5 select f).FirstOrDefault(); // No connection string named 'FileEntities' could be found in the 应用程序配置文件。返回aFile;}
下面是我的服务项目的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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="FileEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=HOOVERS-PC;initial catalog=Interview_MicahHoover;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>我已经尝试删除模型中的"name=“前缀。
发布于 2012-10-23 18:20:34
啊,问题是我的服务项目刚刚建了一个图书馆。使用库的项目中没有连接字符串。我将连接字符串添加到该项目中,它(大部分)可以工作。
保持这样的事情是一个理由,不把事情分解成很多项目,但WCF‘’Reilly的书推荐它。
https://stackoverflow.com/questions/13036510
复制相似问题