简体   繁体   中英

Entity framework unable to connect to network database

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM