Case 1: in a Windows operating system, 10 SQL Server instances are installed, and each instance has about 120 database tutorials. 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: |
Copy code |
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: |
Copy code |
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: