1

i use Entity framework in .net 4 and use this connection in project:

<add name="Database1Entities" connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlClient;pr  ovider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector  y|\Database1.mdf;initial catalog=Database1;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

and show this error:

The underlying provider failed on Open.

Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
Babak Saeedi
  • 157
  • 4
  • 14
  • 4
    Did you create the connection string with the wizard? There are a couple spaces in the `provider connection string` name as well as the value. – Justin Aug 10 '13 at 11:58
  • i have use connection string for Attach database. i delete coennection string wizard and insert my connection. – Babak Saeedi Aug 10 '13 at 12:01
  • Your problem had solved in this link:[The underlying provider failed on open][1] [1]: https://stackoverflow.com/questions/2475008/the-underlying-provider-failed-on-open – DDTBNT Jul 27 '14 at 02:14
  • Have a look at the `InnerException`. In my experience the actual root cause is found there. – Brendan Green May 07 '15 at 23:11

2 Answers2

2

I don't know why you get this error but I use this connection string and I don't have any problem. remember the name of the DbContext class and connection string should be same

<add name="MyDB"
     connectionString="Server=127.0.0.1;User ID=sa;Password=password;Database=Database"
     providerName="System.Data.SqlClient"/>

Saman Qaydi
  • 171
  • 2
  • 7
0

The problem is not in your connection string. This is mostly happen when you are rebuild and clean the project again and again. there is a simple way to solve this problem is that close your local host and wait 2 to 3 minutes. If you face this problem again then close your project and open your project again. Your problem will sort out.