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

发布于 2025-01-20 19:54:15 字数 94 浏览 2 评论 0原文

我正在使用 SQL Server 2012 Express LocalDB。如果实例没有任何活动,它们似乎会在 10 分钟后自动停止。有没有一种干净的方法可以让实例永远运行?

I'm using SQL Server 2012 Express LocalDB. Instances seem to stop automatically after 10 minutes if there is no activity on them. Is there a clean way to keep an instance running forever?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风挽心 2025-01-27 19:54:15

超时是可以通过T-SQL配置的,'用户实例超时'选项:

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

超时以 minute 表示,并且具有65535的最大值 。我敢肯定,设置实例后您需要重新启动该实例。并且不要尝试将其设置为0,它将仅在启动后立即关闭实例,这将使很难将值设置回有用的东西:-)。

来源:此bol文章也要对LocalDB实例。

最终备注

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

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.

凝望流年 2025-01-27 19:54:15

这是如何从命令行中做Krzysztof Kozielczyk的回答。

启动localdb实例。

C:\> sqllocaldb start v11.0
LocalDB instance "v11.0" started.

获取服务器路径,这是实例管道名称。

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

在该服务器上运行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

Here is how to do Krzysztof Kozielczyk's answer from the command line.

Start the localdb instance.

C:\> sqllocaldb start v11.0
LocalDB instance "v11.0" started.

Get the server path, which is the Instance pipe name.

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 an SQL command on that server.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文