0

I have a SQL Server 2008 database on my desktop that I'd like to access on a project developped from my laptop.

I tested the connection to the database from the laptop using the Server Explorer window (Data Connection > Add connection) and everything runs fine. The database is found, and I can access my tables and see the data insde.

I then added an ADO.NET Entity Data Model (= Entity Framework). The integration worked fine: it created the correct classes, I can edit the model, update it regarding the modification I'll pass from the server, ...

Then when I run my project, it needs to read a few data using the classes created by Entity Framework, but it crashes:

Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgment. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=63057;handshake=2;

I looked a bit and found some people having issues with the TCP/IP configuration from the Sql Server Configuration Manager, as explained here. Made the modification, restarted all my services, but it didn't fix my issue.

Does anybody have an idea on how I can fix this (note that I tried with no firewall so it seems not to come from this). Also, if helpful, take into consideration the folowing:

  • the laptop connects through a wifi router (internet box)
  • the project is hosted on the server hardrives
  • the project runs well from the server
13
  • First be certain that the connection string used by the project is correct. Projects are able to use a 'lightweight file' type database and it might be trying to connect to this by default rather than your server Commented Jan 27, 2015 at 23:53
  • The connection string is automatically generated when inserting the ADO.NET Entity Data Model, after testing the connection, so I have no reason to doubt it : <add name="TwitterEntities" connectionString="metadata=res://*/DataBase.TwitterDb.csdl|res://*/DataBase.TwitterDb.ssdl|res://*/DataBase.TwitterDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=***;initial catalog=Twitter;user id=***;password=***;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> it anyway works if I run the project from the server. Commented Jan 27, 2015 at 23:58
  • So in this connection string, data source is set to the name of your desktop SQL Server? (not, for instance, localhost?) Commented Jan 28, 2015 at 0:44
  • @Nick.McDermaid Yes. data source is server\instance. it's anyway automatically generated from the laptop after connecting to the database. Also, it works when run from the server. Commented Jan 28, 2015 at 21:14
  • Just confirming, because there is a lot of confusion around the 'local attach' type connection generated by visual studio (as per the answer suggesting that you detach the DB) From your description I'm running out of ideas. Can you test with a UDL file and see if that sheds any light on it? sophos.com/en-us/support/knowledgebase/65525.aspx Commented Jan 28, 2015 at 22:46

2 Answers 2

1

I found the solution by checking on the option offered in the "Advanced" part of the connection wizard. The Network Library (TCP/IP, Named Pipes, Shared Memory or VIA) can be forced, while it is blank by default (and I guess auto chosen to a wrong option).

I tried all of them, and only the "Named Pipes" worked for me.

The modification can be done manually in the connection string by adding

;network library=dbnmpntw
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure before you run the project that you have detached the database. Do this by right clicking on the database, which is located in the AppData folder, and click on Detach

4 Comments

Confusion reigns....... he is trying to attach to a remote database. Why would you detach the remote database? Then he definitely will not be able to connect to it!!!! Why upvote something that is so misleading?!!
As said by @Nick.McDermaid I guess I wrongly explained my issue somewhere. I don't have anything to detach as the db is not attached at all to my project. Entity Framework, as far as I understand, only creates a model mirroring the database into classes (ex: if I have a "region" table it will create a "region" class that access the data). The db itself remains on my server.
No you explained it fine...the confusion arises because under various circumstances, Entity Framework uses a connection string to attach to a local MDF file (i.e. the string contains AttachDbFileName in it), rather than connecting to an external SQL Server. Most developers are familiar with this and so try to incorrectly troubleshoot issues around this type of connection string. For this question in particular, we do not want to attach to a local MDF file, we want to attach to an external server.
Here's a good example of the two completely different conections strings: stackoverflow.com/questions/7687930/…. This answer is trying to troubleshoot the first AttachDbFilename one, but the question is about the second Data Source one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.