Start/stop the SQL Server service batch processing script

Source: Internet
Author: User
Tags echo 7 net command management studio microsoft sql server management studio sql server management sql server management studio
Provides a batch processing script code that facilitates the website administrator to use SQLServer to start and stop the service. If you need it, please refer to it.

Provides a batch processing script code that facilitates the website administrator to use SQL Server to start/stop services. If you need it, refer to it.

Case 1: In a Windows operating system, 10 SQL Server instances are installed, and each instance has about 120 instances. Now you need to start the services of 10 instances (SQL Server & SQL Server Agent & SQL Server FullText Search) at the same time ). Through SQL Server Configuration Manager, you need an instance and one service to start one by one. How tedious and clumsy the operation is.

Case 2: in Case 1, all instances are started. Soon, it was found that the program was running slowly, even when querying data in the Microsoft SQL Server Management Studio (MSMS) manager, it was like a snail crawling tree. In this case, you need to disable services for SQL Server instances that are not currently used. And then start it when necessary. In some cases, you may encounter services that frequently shut down the instance and start services of another instance to solve the resource shortage problem in Windows.

To solve the complex operation problems in the above case, you can use the Net command to start or stop various SQLServer services, such:

The Code is as follows:
Net Start SQLAgent $ SQL2005DE1/* Start the SQLAgent service in the instance SQL2005DE1 */
Net Stop SQLAgent $ SQL2005DE1/* Stop the SQLAgent service in instance SQL2005DE1 */

According to the Net command, you can write a batch processing script to start various services of each instance. Copy the following code and store the batch file "Start & StopSQLServer. Bat" with the suffix bat ":

The Code is as follows:
View Code
@ Echo off
:
Echo local instance list:
Echo ---------------------------
Echo 1 PC143SQL2005DE1
Echo 2 PC143SQL2005DE2
Echo 3 PC143SQL2005DE3
Echo 4 PC143SQL2005DE4
Echo 5 PC143SQL2005DE5
Echo 6 PC143SQL2005DE6
Echo 7 PC143SQL2005DE7
Echo 8 PC143SQL2005DE8
Echo 9 PC143SQL2005DE9
Echo 10 PC143SQL2005DE10
Echo ---------------------------
Echo operation:
Echo 1 start the service
Echo 0 stops Service
Echo ---------------------------
Echo.
Set/p var2 = enter the operation Action: [1/0]
Set/p var1 = enter the instance number: [1/2/3/4/5/6/7/8/9/10]
If % var1 % = 1 if % var2 % = 1 goto S1
If % var1 % = 2 if % var2 % = 1 goto S2
If % var1 % = 3 if % var2 % = 1 goto S3
If % var1 % = 4 if % var2 % = 1 goto S4
If % var1 % = 5 if % var2 % = 1 goto S5
If % var1 % = 6 if % var2 % = 1 goto S6
If % var1 % = 7 if % var2 % = 1 goto S7
If % var1 % = 8 if % var2 % = 1 goto S8
If % var1 % = 9 if % var2 % = 1 goto S9
If % var1 % = 10 if % var2 % = 1 goto S10
If % var1 % = 1 if % var2 % = 0 goto T1
If % var1 % = 2 if % var2 % = 0 goto T2
If % var1 % = 3 if % var2 % = 0 goto T3
If % var1 % = 4 if % var2 % = 0 goto T4
If % var1 % = 5 if % var2 % = 0 goto T5
If % var1 % = 6 if % var2 % = 0 goto T6
If % var1 % = 7 if % var2 % = 0 goto T7
If % var1 % = 8 if % var2 % = 0 goto T8
If % var1 % = 9 if % var2 % = 0 goto T9
If % var1 % = 10 if % var2 % = 0 goto T10
Echo.
Cls
Goto:
Echo.
: S1
Net Start SQLAgent $ SQL2005DE1/Y
Net Start msftesql $ SQL2005DE1/Y
Goto EndApp
Echo.
: S2
Net Start SQLAgent $ SQL2005DE2/Y
Net Start msftesql $ SQL2005DE2/Y
Goto EndApp
Echo.
: S3
Net Start SQLAgent $ SQL2005DE3/Y
Net Start msftesql $ SQL2005DE3/Y
Goto EndApp
Echo.
: S4
Net Start SQLAgent $ SQL2005DE4/Y
Net Start msftesql $ SQL2005DE4/Y
Goto EndApp
Echo.
: S5
Net Start SQLAgent $ SQL2005DE5/Y
Net Start msftesql $ SQL2005DE5/Y
Goto EndApp
Echo.
: S6
Net Start SQLAgent $ SQL2005DE6/Y
Net Start msftesql $ SQL2005DE6/Y
Goto EndApp
Echo.
: S7
Net Start SQLAgent $ SQL2005DE7/Y
Net Start msftesql $ SQL2005DE7/Y
Goto EndApp
Echo.
: S8
Net Start SQLAgent $ SQL2005DE8/Y
Net Start msftesql $ SQL2005DE8/Y
Goto EndApp
Echo.
: S9
Net Start SQLAgent $ SQL2005DE9/Y
Net Start msftesql $ SQL2005DE9/Y
Goto EndApp
Echo.
: S10
Net Start SQLAgent $ SQL2005DE10/Y
Net Start msftesql $ SQL2005DE10/Y
Goto EndApp
Echo.
: T1
Net Stop MSSQL $ SQL2005DE1/Y
Net Stop msftesql $ SQL2005DE1/Y
Goto EndApp
Echo.
: T2
Net Stop MSSQL $ SQL2005DE2/Y
Net Stop msftesql $ SQL2005DE2/Y
Goto EndApp
Echo.
: T3
Net Stop MSSQL $ SQL2005DE3/Y
Net Stop msftesql $ SQL2005DE3/Y
Goto EndApp
Echo.
: T4
Net Stop MSSQL $ SQL2005DE4/Y
Net Stop msftesql $ SQL2005DE4/Y
Goto EndApp
Echo.
: T5
Net Stop MSSQL $ SQL2005DE5/Y
Net Stop msftesql $ SQL2005DE5/Y
Goto EndApp
: T6
Net Stop MSSQL $ SQL2005DE6/Y
Net Stop msftesql $ SQL2005DE6/Y
Goto EndApp
: T7
Net Stop MSSQL $ SQL2005DE7/Y
Net Stop msftesql $ SQL2005DE7/Y
Goto EndApp
: T8
Net Stop MSSQL $ SQL2005DE8/Y
Net Stop msftesql $ SQL2005DE8/Y
Goto EndApp
: T9
Net Stop MSSQL $ SQL2005DE9/Y
Net Stop msftesql $ SQL2005DE9/Y
Goto EndApp
: T10
Net Stop MSSQL $ SQL2005DE10/Y
Net Stop msftesql $ SQL2005DE10/Y
Goto EndApp
: EndApp
Set/p var3 = continue operation: [y/n]
If % var3 % = y goto:

The following shows the batch processing scripts for starting and stopping 10 SQL Server instances on pc143. Run the script below to start one of the Instance services in PC143, PC143SQL2005DE4:

SQL2005DE4:

Disabling the instance service is similar to starting the instance service, for example:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.