How to prevent SQL Server LocalDB auto shutdown?

The timeout is configurable via T-SQL with 'user instance timeout' option:

sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'user instance timeout', 5;
GO

The timeout is expressed in minutes and has a maximum value of 65535. I’m pretty sure you need to restart the instance after setting it. And don’t try setting it to 0, it will just make the instance shut down immediately after starting, which will make it hard to set the value back to something useful :-).

Source: this BOL article containing other useful information on User Instances that are applicable to LocalDB instances as well.

Final Remark

If you need something that’s always running and starts whenever a computer starts you might just consider using regular, service-based, instance of SQL Server Express.

Leave a Comment