3

I am successfully running tests through the the WCF Test Client, until I try to pull in data with 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

...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.

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.

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.

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" />
5
  • 1
    Could you share your connection string? Commented Nov 17, 2011 at 11:39
  • Do you have "Drop Database" as Initializer enabled and MS SQL Management Studio open at the same time? That would cause such an exception because you cant drop the database on that occasion, and EF fails out. Commented Nov 17, 2011 at 11:39
  • @flipchart - I have edited above to add that Commented Nov 17, 2011 at 12:17
  • @UrbanEsc - I didn't really understand what you're saying, so I closed sql server studio and tried again, with no success. Thanks though. Commented Nov 17, 2011 at 12:26
  • The connection string doesn't have password for the sa user. Commented Nov 17, 2011 at 14:52

4 Answers 4

5

This error means 100% a problem in your connection string.

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.
Than, in you web/app.Config, you have a Connection String you can copy+paste to your own project

Sign up to request clarification or add additional context in comments.

1 Comment

Note that The underlying provider failed on Open may also be because of authorization issues. The inner exception will state if that is the case. One example where this may occur is when UAC is on and the data file is stored in the Program Files directory.
1

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/

Comments

1

Well I had the same error for days... actualy for two days and Yes I found the solution 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.

I might face some other issues later on, still I would say a Good Start :-)!

Comments

0

I was remove "integrated security=True;" solved this way.

2 Comments

I do not see integrated security=True; anywhere in the question. Could you elaborate and make your answer clear and easier to understand?
You should delete interated secutriy and add User ID and Password. This my connection string : <connectionStrings><add name="PettyDBEntities" connectionString="metadata=res://*/PettyModel.csdl|res://*/PettyModel.ssdl|res://*/PettyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=WIN-COO1ETVI1E6;initial catalog=PettyDB; integrated security=True; User ID=admin;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.