Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 14, 2012 12:43 PM by PuzzledSpark
Nov 11, 2012 09:07 PM|LINK
I have a site that someone else created for me for which they have now given me the Visual Studio source code.
I build the project on my machine without errors but at run time I get an error saying:
The underlying provider failed on Open:
A first chance exception of type 'System.Data.EntityException' occurred in System.Data.Entity.dll
Basically from what I can tell it's struggling to connect to the database?
In Web config I have:
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DBS_MyWebsite;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="DBS_MyWebsiteEntities" connectionString="metadata=res://*/ModelCBS.csdl|res://*/ModelCBS.ssdl|res://*/ModelCBS.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;Initial Catalog=DBS_MyWebsite;Integrated
Security=SSPI;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Any ideas what I can do to resolve this? Also I haven't created the database on my system, I've just got the source files they gave me but I don't know whether that includes the SQL server database or whether I'm supposed to create my own copy on my machihne
Nov 12, 2012 12:55 PM|LINK
Your connection string is expecting the database to be in local machine
"Data Source=.\SQLEXPRESS" If you do not have the database in your local machine then either you need to create the databse in your machine or change the connection string to point to any exising database.
Nov 12, 2012 02:23 PM|LINK
I can suggest you to try as
1. Fully qualify your SQL server (.\SQLEXPRESS) to as serverName\SqlInstance. And it would be like this "hp-User\SQLEXPRESS" . You can easily find/get it from connecting your SSMS where it asks for user name & password.
2. Avoid IntegratedSecurity and use user id /password. This also solve if you are working in IIS. If you can't avoid use of IntegratedSecurity then restart your IIS and recheck.
3. Change the way you are using with DataBaseEntities. Open your connection inside them.
I would suggest you to check with user id & password.
Refer illustrated solution over here - http://blogs.msdn.com/b/dataaccesstechnologies/archive/2012/08/09/error-quot-the-underlying-provider-failed-on-open-quot-in-entity-framework-application.aspx
Nov 14, 2012 12:43 PM|LINK
Yep you are right - I created the database (using a T-SQL script) and got it to work.
There's also an entity framework model in the source files which I haven't looked into but I'm guessing I should have used that to create the database somewhoe. Will google it..