Search code examples
c#sql-serverentity-frameworktimeout

EF, SQL Server - Connection Timeout Expired. The timeout period elapsed during the post-login phase


I've created an ASP.NET MVC project that uses Entity Framework and Identity.

The problem is that when I debug my project, I get an error.

(note: If I delete my DB from SQL Server Object Explorer and run it again this error don't show up, but I don't want to manually delete it every time)

Error:

Connection Timeout Expired. The timeout 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=15; handshake=3; [Login] initialization=0; authentication=2; [Post-Login] complete=14991

Connection string:

<add name="MovieReviewsDb" 
     providerName="System.Data.SqlClient" 
     connectionString="Data Source(LocalDb)\v11.0;AttachDbFileName=|DataDirectory|\MovieReviewsDb.mdf;Initial Catalog=MovieReviewsDb;Integrated Security=SSPI;MultipleActiveResultSets=True" />   

I've set custom initializer that inherits from DropCreateDatabaseAlways. I have overridden the Seed method where I populate the database with 3 records and creates default roles and users (Identity).

(note: my DbContext inherits from IdentityDbContext)

I'm stuck at this for several hours and searched through a lot of similar posts (like this one) but I can't find an answer.

Is it possible to set a bigger timeout (maybe It takes too long and the timeout is reached) and how?


Solution

  • I think I've finally figured it out.

    I've added ;Connection Timeout=120; to my connection string and it works. I guess it just needed more time.