Timeout elapsed on the underlying provider, resulting in an entity exception.

asp.net-mvc c#-4.0 connection-string entity-framework sql

Question

OK, I'm stumped. I am trying to create a .NET Winforms app to talk to a database via Entity Framework. I originally created a ASP.NET MVC3 app (with a seperate DAL layer) that can talk to the database after initially failing. SO the first time that it tries to open the connection, it times out. If I then hit F5 in the browser, it connects fine! I referenced this DAL in my Winforms app.

  • I can connect to the database via SQL Auth in SQL Management Studio fine.
  • I can create the ADO.NET Data classes in VS2010 (it connects, gets the tables and stores the connection string in the app.config).
  • However, once I run the Winforms app, I am unable to connect. I get the mentioned exception with an InnerException of "Timeout expired."

I copied the connection string from the web.config to the app.config.

The SQL database is hosted on my Windows Home Server called SERVER. I am in a Workgroup (no Domain). I uses SERVER\SQLEXPRESS in Management Studio and VS to successfully connect to it.

Things I've tried:

  • Disable the firewall on the client machine.
  • Enabled DTC on the server and added msdtc.exe to the exclusion list on the server.
  • Made sure Named Pipes in enabled on the SQL server instance.
  • Tried different SQL users.
  • Tried different ways of constructing the connection in C#.
  • Generated a new ADO.NET Data class local to my WinForms project (not referencing the DAL). VS connects fine, reads the tables, generates the code. But the running app causes a "Timeout Expired" SqlException.

So running the app is unsuccessful in connecting. When I watch the app in ProcessExplorer I can see an entry in the TCP window when it tries to Connect on remote port 4845 with a SYN_SENT message. Not sure if that's right.

I've google'd and bing'd this for the last few days, I've read all the articles and replies here on Stackoverflow that mention this exception, but I have hit a wall.

This is the ConnectionString that VS generated after reading the DB:

<add name="LLDBEntities" connectionString="metadata=res://*/LLDB.csdl|res://*/LLDB.ssdl|res://*/LLDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SERVER\SQLEXPRESS;initial catalog=LLDB;persist security info=True;user id=sa;password=sapwd;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Any help appreciated, even any hints on how to figure out what's happening.

1
0
4/4/2012 9:39:24 PM

Accepted Answer

Ok, solved.

I noticed that it would actually connect on the second attempt with the same app and connection. At that point I found this link: http://kromey.us/2011/06/microsoft-sql-server-2008-times-out-on-first-connection-attempt-447.html

So I opened the firewall port listed under IPAll Dynamic Port in SQL Server Configuration Manager on the TCP/IP Properties for the instance and now it all works fine. I still don't know why it would get through on the second attempt....

1
4/6/2012 12:39:26 AM

Popular Answer

Your connection string looks more like a connection string to an SQL Server, rather than SQL Express.

Have a look at this for a connection string to SQL Express: SQL Server Express connection string for Entity Framework Code First



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow