visual-studio 如何直接从 Visual Studio 启动/停止本地 SQL Server 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1161305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start/stop local SQL Server service directly from Visual Studio?
提问by User
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.
我相信和许多开发人员一样,我的 PC 上同时安装了 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。
回答by adrianbanks
In Visual Studio, go to Tools -> External Tools...
Click the add button, and enter Start SQL Serverfor the title and for the command put:
C:\WINDOWS\system32\net.exe
For the arguments, put:
start mssqlserver
Untick "Close on exit" and tick "Use output window".
Repeat steps 2-4 to create the stop command, but for the arguments put:
stop mssqlserver
在 Visual Studio 中,转到工具 -> 外部工具...
单击“添加”按钮,并为标题和命令输入“启动 SQL Server”:
C:\WINDOWS\system32\net.exe
对于参数,输入:
启动 mssqlserver
取消勾选“退出时关闭”并勾选“使用输出窗口”。
重复步骤 2-4 以创建停止命令,但对于参数 put:
停止 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将它们称为this,所以你必须弄清楚选择哪个) 到工具栏。
回答by Keith Adler
You should just simply go to the Services Manager, however to get there from VS 2008:
您应该只需转到服务管理器,但是要从 VS 2008 到达那里:
- Go to Server Explorer Tab
- Expand out the Servers section
- Expand out the name of your computer
- Right click on the Services section and select Launch Services Manager
- From Services Manager, select SQL Server and do whatever Start, Stop, Restart action you wish to achieve
- 转到服务器资源管理器选项卡
- 展开服务器部分
- 展开您的计算机名称
- 右键单击服务部分并选择启动服务管理器
- 从服务管理器中,选择 SQL Server 并执行您希望实现的任何启动、停止、重新启动操作
Another way would be the commaind line approach of:
另一种方法是命令行方法:
net stop "SQL Server (MSSQLSERVER)" net start "SQL Server (MSSQLSERVER)"
净停止“SQL Server(MSSQLSERVER)”净启动“SQL Server(MSSQLSERVER)”

