0

I've got the following error...

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I can use the same connection string to connect to the same database using a SqlDataSource but EntityFramework gives the above quoted error!!

The only complication is that I'm providing the name of the db to the data context in its constructor and that's never not worked before.

Any ideas?

Cheers, Ian.

Ian Warburton
  • 14,318
  • 20
  • 99
  • 173
  • What about showing how you define the connection string and how you define and call the constructor? – Ladislav Mrnka Jun 09 '11 at 20:39
  • Thanks for your reply. Does EntityFramework have specific requirements for the connection string? – Ian Warburton Jun 09 '11 at 20:44
  • It depends if you are using EDMX file or not. – Ladislav Mrnka Jun 09 '11 at 20:46
  • Nope... no edmx. Just an app that won't connect to a database with EF despite every other client being able to do so! It will connect to a staging db but not the live one! – Ian Warburton Jun 09 '11 at 20:53
  • How do you provide the name of the database? Why don't you left it in the connectin string? – Ladislav Mrnka Jun 09 '11 at 21:03
  • Because otherwise it generates a long db name based on the namespace of the db context class. I think I'm onto something... weeks ago I discovered that you have to set the name of the db connection string to the name of the db and with my current live app they don't match!! But with my local version using SQLExpress they don't match either so why's that been working? – Ian Warburton Jun 09 '11 at 21:11
  • See here... http://stackoverflow.com/questions/5790325/entityframework-where-is-the-connection-string – Ian Warburton Jun 09 '11 at 21:12
  • The name of the connection string must be same as the name of your context not the database. – Ladislav Mrnka Jun 09 '11 at 21:12
  • No... not if you rename the db! Then the connection string id must be the same as the database. I've just got this working now actually. But the real mystery here is why the connection string on my local machine was found by EF even though it is not the same as the db name or the db context....? – Ian Warburton Jun 09 '11 at 21:25
  • I think I get it... if it can't find a connection string with the supplied name, it will look for a db of the same name on the local host. If it can't find it on the local host it creates a new db. If your db is not local and you don't have a local host then it says it can't connect to the server. I wonder if the error message was actually it not finding the local host?? Anyhow, this is all really confusing. I don't think variables should have multiple meanings. – Ian Warburton Jun 09 '11 at 22:56

0 Answers0