Set custom timeout for code first Migrations Entity Framework (Core 2.0)

Allow customizing timeout for migrations.

Sometimes a migration takes more time then your default timeout of your database connection. In such a case you do want to increase the timeout for the migration to be able to complete, but you do not want to change the timeout for your normal operations.

You can increase the timeout before you call the Migrations with by setting the timeout on the Database context:

using (var context = new DispatchingDbContext(_configuration))
    await context.Database.MigrateAsync().ConfigureAwait(false);

When running your migrations you see the following error:

+ $exception {System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. —> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

This way do only have a different timeout when you are running the migrations on the database.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s