i'm using ado.net entity framework 4.1 to connect to a sql server 2008 r2 64 bits instance located on my computer. but when i try to initialize the connection i get the following exception:

{"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}

the sql service for that instance is running, also sql browser. added exceptions to 1433 port and sql browser. in sql server configuration manager, shared memory is enabled, also named pipes and tcp/ip.

these are my app.config connection string: using a user and password:

 <connectionStrings>
<add name="DbTerminalContext" connectionString="Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;User Id=sa;Password=password;MultipleActiveResultSets=True"
  providerName="System.Data.SqlClient" />

this is using windows identity:

<add name="DbTerminalContext" connectionString="Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;Trusted_Connection=True;MultipleActiveResultSets=True"
  providerName="System.Data.SqlClient" />

i tried using insted of URIEL, .\SQLIT64, also localhost\SQLIT64 and i simply cannot connect.

i've searched and tried various solutions found in here and in other places. no solution whatsoever. so can anyone help me? thanks in advance

share|improve this question
Is that instance name, definitely correct? – Kieren Johnstone Nov 26 '12 at 23:54
yes. i'm connected currently connected using sql server management studio – jonniebigodes Nov 27 '12 at 0:00
Then are you sure your connection string is being used? E.g. set it to something empty or invalid, do you get a different message? (Checking that you are editing the right string) – Kieren Johnstone Nov 27 '12 at 7:32
feedback

2 Answers

Check that NamedPipes is enabled in the Sql Server Configuration Manager

(Start -> SQL* -> Configuration -> SQL Server Configuration Manager, then click the SQL Server Network Configuration node).

share|improve this answer
in the original post i mentioned this. named pipes is in fact enabled – jonniebigodes Nov 27 '12 at 0:38
feedback

Try adding metadata resource information to your connection string.

Assuming your Entity Data Model is called "TerminalDataEntities.edmx" there are three files generated in the obj\Debug\edmxResourcesToEmbed Folder of your project.

  • TerminalDataEntities.csdl
  • TerminalDataEntities.ssdl
  • TerminalDataEntities.msl

To add these resources to your connection string, you need to change the format of the add-Tags connectionString-Value.

The metadata:

metadata=res://*/TerminalDataEntities.csdl|res://*/TerminalDataEntities.ssdl|res://*/TerminalDataEntities.msl;

The provider:

provider=System.Data.SqlClient;

and the provider connection string:

provider connection string=&quot;Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;Trusted_Connection=True;MultipleActiveResultSets=True&quot;

Put it all together: (With Windows Identity)

<add name="DbTerminalContext" connectionString="metadata=res://*/TerminalDataEntities.csdl|res://*/TerminalDataEntities.ssdl|res://*/TerminalDataEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;Trusted_Connection=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

(Without Windows Identity)

<add name="DbTerminalContext" connectionString="metadata=res://*/TerminalDataEntities.csdl|res://*/TerminalDataEntities.ssdl|res://*/TerminalDataEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;User Id=sa;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Hope this works.

share|improve this answer
i'm using code first for what i've been reading i dont need the metadata part – jonniebigodes Nov 27 '12 at 1:12
i think i've found the problem. the problem isn't with the connection but with the my dbcontext class. i'm using this code: using (var tmp= new DbTerminalContext("DbTerminalContext"){} instead of loading the correct connection string, the following is assumed: "Data Source=.\\SQLEXPRESS;Initial Catalog=DbTerminalContext;Integrated Security=True;MultipleActiveResultSets=True" that server instance is not activated. now the problem presents itself with loading the correct connection string from app.config – jonniebigodes Nov 27 '12 at 1:15
use var tmp= new DbTerminalContext("Name=DbTerminalContext"){} - notice "Name" in the parameter - it tells CodeFirst to take the connection string with the given name from the config file. – Pawel Nov 27 '12 at 6:58
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.