Friday, December 20, 2013

{System.Data.EntityException: The underlying provider failed on Open.

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

No comments: