仅在启动SSMS时启动SQL Server

问题描述 投票:0回答:1

我最近安装了SQL Server 2019,并且在启动时占用了不错的3 GB或RAM。

我只是在家中将其用于个人用途,因此已将其关闭。

我想知道是否有一种方法可以在PowerShellCMD中写一个脚本:

  1. 启动SSMS时启动SQL Server (MSSQLSERVER)
  2. 关闭SSMS时停止SQL Server (MSSQLSERVER)
sql-server powershell cmd scripting ssms
1个回答
0
投票

您可以创建脚本来启动服务器(例如批处理文件或PowerShell),然后运行SSMS.exe。

您也可以在以下位置启动SQL Server引擎:

命令提示符

net start "SQL Server (MSSQLSERVER)"

PowerShell

# Get a reference to the ManagedComputer class.
CD SQLSERVER:\SQL\computername
$Wmi = (get-item .).ManagedComputer

$DfltInstance = $Wmi.Services['MSSQLSERVER']

# Display the state of the service.
$DfltInstance

# Start the service.
$DfltInstance.Start();

# Wait until the service has time to start.
# Refresh the cache.  
$DfltInstance.Refresh();

# Display the state of the service.
$DfltInstance

# Stop the service.
$DfltInstance.Stop();

# Wait until the service has time to stop.
# Refresh the cache.
$DfltInstance.Refresh();

# Display the state of the service.
$DfltInstance

关于docs的更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.