Entity Framework 5.0 with DbContext in the code tried to have access data as data Access layer code of a WCF service, the following error happened:
{System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Connection Timeout Expired.
The time out period elapsed during the post-login phase.
The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections.
The duration spent while attempting to connect to this server was - [Pre-Login] initialization=50; handshake=1215; [Login] initialization=0; authentication=14; [Post-Login] complete=13022;
---> System.ComponentModel.Win32Exception: The wait operation timed out
It didn't have Transaction around the code, if I had a TransactionScope around the code then it treat connections as multiple ones using a distributed transaction which force open/close connections with each call. But without the transaction I needed to add opening connection code.
using (MyEntities ctx = new MyEntities())
{
#region Added to work when Transaction is not around
ctx.Database.Connection.Open();
#endregion
courseList = ctx.MyMethod(MyParam).ToList();
}
![Share/Bookmark](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vC7tXQRimIOyoeveq9N1XU_glr1kZo2pd1U9sdiIeKSh5X1fj4O90CXtjXTR4xNx9QbulXHlDZpZgRDdXs0BMbzWPDYr48c0E4gICHGmBaRcTwbSwK8uZGUq4=s0-d)
{System.Data.EntityException: The underlying provider failed on Open.