简体   繁体   English

WCF和实体框架和SQL Server - “底层提供程序在Open上失败”

[英]WCF & Entity Framework & SQL Server - “The underlying provider failed on Open”

I am successfully running tests through the the WCF Test Client, until I try to pull in data with Entity Framework. 我通过WCF测试客户端成功运行测试,直到我尝试使用Entity Framework提取数据。

To make sure I'm not doing anything stupid, I downloaded the sample code from this tutorial, which is doing something similar: http://www.codeproject.com/KB/WCF/WCFandEF.aspx 为了确保我没有做任何愚蠢的事情,我从本教程中下载了示例代码,该代码执行类似的操作: http//www.codeproject.com/KB/WCF/WCFandEF.aspx

...and when I run it, I get the same error in a similar place: ...当我运行它时,我在类似的地方得到了同样的错误:

var productEntity = (from p in context.ProductEntities 
                     where p.ProductID == id
                     select p).FirstOrDefault();

The error is 错误是

The underlying provider failed on Open. 底层提供程序在Open上失败。

I can open the database fine from a "normal application" with the same connection string, it seems to be specific accessing the DB from the WCF test client. 我可以使用相同的连接字符串从“普通应用程序”打开数据库,它似乎是从WCF测试客户端特定访问数据库。

Research here and on Google for "The underlying provider failed on Open." 在这里和谷歌上进行研究“基础提供商在开放时失败了”。 usual indicates that it's a connection string problem, but I'm pretty sure it's not in this case. 通常表示这是一个连接字符串问题,但我很确定它不是在这种情况下。

So now I expect it's some sort of permissions problem. 所以现在我希望它是某种权限问题。

I am using SQL Server and Windows 7, with visual studio 2010. 我正在使用Visual Studio 2010的SQL Server和Windows 7。

I have been banging my head since yesterday, so any help or protective head gear appreciated. 从昨天开始,我一直在敲打我的脑袋,所以任何帮助或保护头盔都会受到赞赏。

Edited to include connection string 编辑包含连接字符串

<add name="NorthwindEntities" 
     connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider
connection string=&quot;Data Source=localhost;Initial Catalog=Northwind;User ID=sa;MultipleActiveResultSets=True&quot;" 
     providerName="System.Data.EntityClient" />

This error means 100% a problem in your connection string. 此错误表示连接字符串中存在100%问题。

A good way to create a surely working connection string is to create a new(dummy) project, add an Entity Framework Data Model to it, select "Generate Model from Database", select your required connection, and click "Test Conntection" to be sure it works. 创建一个可靠的连接字符串的好方法是创建一个新的(虚拟)项目,向其添加一个实体框架数据模型,选择“从数据库生成模型”,选择所需的连接,然后单击“测试连接”为确定它有效。
Make sure ""Save entity conection settings in App.Config as:..." is ticked. 确保选中“”将App.Config中的实体连接设置保存为:...“。
Than, in you web/app.Config, you have a Connection String you can copy+paste to your own project 在web / app.Config中,你有一个连接字符串,你可以复制+粘贴到你自己的项目

Have you tried inserting the database password into the connection string? 您是否尝试将数据库密码插入连接字符串? It worked for me. 它对我有用。

Reference: http://stack247.wordpress.com/2011/03/02/entity-framework-exception-the-underlying-provider-failed-on-open/ 参考: http//stack247.wordpress.com/2011/03/02/entity-framework-exception-the-underlying-provider-failed-on-open/

Well I had the same error for days... actualy for two days and Yes I found the solution Alhamdulillah.. 好吧,我有几天相同的错误...实际两天,是的, 我找到了解决方案 Alhamdulillah ..

As for me... I had Windows Authentication set on my Entity Service Connection.. So What I did was I went to IIS 7 Application Pool Advanced Settings for the web service... Changed the Identity from 'ApplicationPoolIdentity' to 'Network Service' and I setup my current user name and password as well. 至于我...我在我的实体服务连接上设置了Windows身份验证..所以我做的是我去了IIS 7应用程序池高级设置的Web服务...将身份从'ApplicationPoolIdentity'更改为'网络服务'我也设置了我当前的用户名和密码。

I might face some other issues later on, still I would say a Good Start :-)! 我可能会在以后遇到其他一些问题,但我仍然会说一个好的开始:-)!

I was remove "integrated security=True;" 我删除了“integrated security = True;” solved this way. 这样解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架和SQL Server CE-基础提供程序在打开时失败 - Entity Framework & SQL Server CE - Underlying Provider Failed On Open 实体框架:基础提供程序在打开时失败-通过WCF服务 - Entity Framework: The underlying provider failed on Open - through WCF service 基础提供程序无法打开-WPF和实体框架 - The underlying provider failed to open - WPF and Entity FrameWork 实体框架底层提供程序在打开时失败 - Entity Framework The underlying provider failed on Open 实体框架异常“底层提供程序打开失败” - Entity Framework Exception “The underlying provider failed on Open” 基础提供程序在实体框架中打开时失败 - The underlying provider failed on Open in entity framework connection 实体Framewok-基础提供程序在打开时失败-SQL - Entity Framewok - The underlying provider failed on Open - SQL SQLite&Entity Framework 6“基础数据提供程序无法打开” - SQLite & Entity Framework 6 “The underlying data provider failed to open” 实体框架给出异常:“底层提供程序在打开时失败。” - Entity Framework giving exception : “The underlying provider failed on Open.” 带有 Unity 的实体框架“底层提供程序在 Open 上失败”。 - Entity framework with Unity “The underlying provider failed on Open.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM