William
William

Reputation: 8067

Can't connect to any SQL instances with latest EntityFramework

I've just updated my EntityFramework from EntityFramework.4.1.10331.0 to EntityFramework.4.1.10715.0

With this version I can't connect to a single database instance on my local machine or a variety of remote machines, using either integrated security or SQL based authentication.

Connections still work fine if I use the the old 4.1.10331.0 release.

The specific error I get is below, however the instances I'm connecting to are all default instances.

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)

My SQL based authentication connection string looks as follows

Server=localhost;Database=dbname;UID=username;PWD=password;

Has anyone else ran across this or can anyone suggest possible causes?

Upvotes: 1

Views: 1092

Answers (2)

William
William

Reputation: 8067

I managed to get this working however I'm still not totally sure what the reasoning behind it is. I think it may perhaps be related to a Provider configuration as suggested by Yuck.

Against the 4.1.10331.0 build I was setting the connectionstring on the DBContext as follows and it worked fine.

Context.Database.Connection.ConnectionString = "Server=localhost;Database=dbname;UID=username;PWD=password;"

However, against build 4.1.10715.0 this would result in the error: 26 - Error Locating Server/Instance Specified exception.

I now pass the connectionstring into the constructor of my context, which in turn passed that onto its base constructor. Everything then works fine as expected.

public TestContext(string nameOrConnectionString) : base(nameOrConnectionString) {}

...

var context = new TestContext("Server=localhost;Database=dbname;UID=username;PWD=password;")

Upvotes: 0

Yuck
Yuck

Reputation: 50835

Make sure your connection string has the provider attribute specified:

SERVER=localhost;DATABASE=dbname;USER ID=username;
PASSWORD=password;PROVIDER=System.Data.SqlClient;

Upvotes: 2

Related Questions