如何直接从Visual Studio启动/停止本地SQL Server服务?

时间:2021-11-13 18:22:23

I believe like many developers I have both Visual Studio and SQL Server installed on my PC. Since I use the PC for various tasks not just for development, SQL Server is by default stopped until I need it for another session of development.

我相信很多开发人员都在我的电脑上安装了Visual Studio和SQL Server。由于我将PC用于各种任务而不仅仅用于开发,因此默认情况下SQL Server会停止,直到我需要它用于另一个开发会话。

Currently I go directly to Administrative Tools->Services to start/stop SQL Server. Not that it bothers me, but it would have been much better if I could have something like this standard start/stop button directly in Visual Studio toolbar. Is it possible somehow?

目前我直接进入管理工具 - >服务来启动/停止SQL Server。这并不困扰我,但如果我可以在Visual Studio工具栏中直接使用类似这个标准的开始/停止按钮,那会好得多。有可能吗?

Another idea would be to start the service at the start of Visual Studio and automatically stop it when I close the application. Is this behavior easier to achieve?

另一个想法是在Visual Studio启动时启动服务,并在关闭应用程序时自动停止它。这种行为更容易实现吗?

I have VS 2008 and SQL 2008.

我有VS 2008和SQL 2008。

2 个解决方案

#1


  1. In Visual Studio, go to Tools -> External Tools...

    在Visual Studio中,转到“工具” - >“外部工具”...

  2. Click the add button, and enter Start SQL Server for the title and for the command put:

    单击“添加”按钮,然后为标题和命令put输入“启动SQL Server”:

    C:\WINDOWS\system32\net.exe

  3. For the arguments, put:

    对于参数,放:

    start mssqlserver

  4. Untick "Close on exit" and tick "Use output window".

    取消“退出时关闭”并勾选“使用输出窗口”。

  5. Repeat steps 2-4 to create the stop command, but for the arguments put:

    重复步骤2-4以创建stop命令,但对于参数put:

    stop mssqlserver

You know have two external tools configured which you can run by selecting them from the Tools menu in Visual Studio.

您知道配置了两个外部工具,您可以通过从Visual Studio的“工具”菜单中选择它们来运行这些工具。

You can also add a shortcut button in any toolbar by right-cliking on the toolbar area, selecting customise, and then dragging the relevant external tool link (unfortunately VS refers to them as this, so you will have to figure out which one to choose) to a toolbar.

您还可以通过右键单击工具栏区域,选择自定义,然后拖动相关的外部工具链接在任何工具栏中添加快捷按钮(不幸的是,VS将它们称为这样,因此您必须确定选择哪一个)到工具栏。

#2


You should just simply go to the Services Manager, however to get there from VS 2008:

您应该只是去服务经理,然而从VS 2008到达那里:

  1. Go to Server Explorer Tab
  2. 转到Server Explorer选项卡

  3. Expand out the Servers section
  4. 展开“服务器”部分

  5. Expand out the name of your computer
  6. 展开计算机的名称

  7. Right click on the Services section and select Launch Services Manager
  8. 右键单击Services部分,然后选择Launch Services Manager

  9. From Services Manager, select SQL Server and do whatever Start, Stop, Restart action you wish to achieve
  10. 从服务管理器中,选择SQL Server并执行您希望实现的启动,停止,重新启动操作

Another way would be the commaind line approach of:

另一种方式是commaind line方法:

net stop "SQL Server (MSSQLSERVER)" net start "SQL Server (MSSQLSERVER)"

net stop“SQL Server(MSSQLSERVER)”网络启动“SQL Server(MSSQLSERVER)”

#1


  1. In Visual Studio, go to Tools -> External Tools...

    在Visual Studio中,转到“工具” - >“外部工具”...

  2. Click the add button, and enter Start SQL Server for the title and for the command put:

    单击“添加”按钮,然后为标题和命令put输入“启动SQL Server”:

    C:\WINDOWS\system32\net.exe

  3. For the arguments, put:

    对于参数,放:

    start mssqlserver

  4. Untick "Close on exit" and tick "Use output window".

    取消“退出时关闭”并勾选“使用输出窗口”。

  5. Repeat steps 2-4 to create the stop command, but for the arguments put:

    重复步骤2-4以创建stop命令,但对于参数put:

    stop mssqlserver

You know have two external tools configured which you can run by selecting them from the Tools menu in Visual Studio.

您知道配置了两个外部工具,您可以通过从Visual Studio的“工具”菜单中选择它们来运行这些工具。

You can also add a shortcut button in any toolbar by right-cliking on the toolbar area, selecting customise, and then dragging the relevant external tool link (unfortunately VS refers to them as this, so you will have to figure out which one to choose) to a toolbar.

您还可以通过右键单击工具栏区域,选择自定义,然后拖动相关的外部工具链接在任何工具栏中添加快捷按钮(不幸的是,VS将它们称为这样,因此您必须确定选择哪一个)到工具栏。

#2


You should just simply go to the Services Manager, however to get there from VS 2008:

您应该只是去服务经理,然而从VS 2008到达那里:

  1. Go to Server Explorer Tab
  2. 转到Server Explorer选项卡

  3. Expand out the Servers section
  4. 展开“服务器”部分

  5. Expand out the name of your computer
  6. 展开计算机的名称

  7. Right click on the Services section and select Launch Services Manager
  8. 右键单击Services部分,然后选择Launch Services Manager

  9. From Services Manager, select SQL Server and do whatever Start, Stop, Restart action you wish to achieve
  10. 从服务管理器中,选择SQL Server并执行您希望实现的启动,停止,重新启动操作

Another way would be the commaind line approach of:

另一种方式是commaind line方法:

net stop "SQL Server (MSSQLSERVER)" net start "SQL Server (MSSQLSERVER)"

net stop“SQL Server(MSSQLSERVER)”网络启动“SQL Server(MSSQLSERVER)”