如何防止SQL Server LocalDB自动关机?

use*_*865 21 sql-server localdb

我正在使用SQL Server 2012 Express LocalDB.如果没有活动,实例似乎会在10分钟后自动停止.是否有一种干净的方法来保持实例永远运行?

Krz*_*zyk 29

超时可通过T-SQL配置'user instance timeout'选项:

sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'user instance timeout', 5;
GO
Run Code Online (Sandbox Code Playgroud)

超时以分钟表示,最大值为65535.我很确定您需要在设置后重新启动实例.并且不要尝试将其设置为0,它只会在启动后立即关闭实例,这将使得很难将值设置回有用的东西:-).

来源:此BOL文章包含有关适用于LocalDB实例的用户实例的其他有用信息.

最后的评论

如果您需要一些始终运行并在计算机启动时启动的东西,您可以考虑使用常规的,基于服务的SQL Server Express实例.


Sha*_*tin 11

以下是如何从命令行执行Krzysztof Kozielczyk的回答.

启动localdb实例.

C:\> sqllocaldb start v11.0
LocalDB instance "v11.0" started.
Run Code Online (Sandbox Code Playgroud)

获取服务器路径,即实例管道名称.

C:\> sqllocaldb info v11.0
Name:               v11.0
Version:            11.0.3000.0
Shared name:        IIS_DB
Owner:              DESKTOP-AAAT5QS\bigfo
Auto-create:        Yes
State:              Running
Last start time:    2/17/2016 12:06:43 PM
Instance pipe name: np:\\.\pipe\LOCALDB#SH9D87FB\tsql\query
Run Code Online (Sandbox Code Playgroud)

在该服务器上运行SQL命令.

C:\> sqlcmd -S np:\\.\pipe\LOCALDB#SH9D87FB\tsql\query

1> sp_configure 'show advanced options', 1;
2> GO

Configuration option 'show advanced options' changed from 1 to 1. 
Run the RECONFIGURE statement to install.

1> RECONFIGURE;
2> GO

1> sp_configure 'user instance timeout', 5;
2> GO

Configuration option 'user instance timeout' changed from 5 to 5. 
Run the RECONFIGURE statement to install.

1> RECONFIGURE;
2> GO

> exit
Run Code Online (Sandbox Code Playgroud)

  • 要查看当前设置,请使用“sp_configure '用户实例超时'” (2认同)