启动/停止SQL Server服务的批处理脚本
提供一个方便网站管理员用的程序 SQL Server 启动/停止服务的批处理脚本代码,有需要的朋友可以参考一下。
案例一:在一个Windows操作系统中,安装有10个SQL Server实例,每一个实例存在大约120个。现在要同时启动10个实例的服务(SQL Server & SQL Server Agent & SQL Server FullText Search)。通过SQL Server Configuration Manager,需要一个实例,一个服务的一一启动。那是多么繁琐、笨拙的操作。
案例二:在案例一的场景,启动了全部的实例。不久,就发现程序运行缓慢,即使在Microsoft SQL Server Management Studio(MSMS)管理器查询数据,都有如蜗牛爬树。这时候,需要关闭一些暂时不用的SQL Server实例的服务。等需要的时候再启动。一些时候,可能会碰到经常要关闭这个实例的服务,启动另外实例的服务,以便解决Windows系统资源紧张的问题。
解决上面案例繁琐的操作问题,可以考虑通过Net命令,来启动或停止各个SQLServer服务,如:
代码如下 | 复制代码 |
net Start SQLAgent$SQL2005DE1 /*启动实例SQL2005DE1中的SQLAgent服务*/ net Stop SQLAgent$SQL2005DE1 /*停止实例SQL2005DE1中的SQLAgent服务*/ |
根据Net命令,可以通过编写一个批处理脚本实现,启动各个实例的各服务。Copy下面的代码,存储为后缀名为Bat的批处理文件“Start&StopSQLServer.bat”:
代码如下 | 复制代码 |
View Code @echo off :a echo 本机的实例列表: 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 操作动作: echo 1 启动服务 echo 0 停止服务 echo --------------------------- echo. Set/p var2=请输入操作动作:[1/0] Set/p var1=请输入实例编号:[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 a: 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=是否继续操作:[y/n] If %var3% == y goto a: |
这里演示了PC143上的10个SQL Server实例启动、停止的批处理脚本。下面来运行这个脚本,启动PC143上其中一个实例服务PC143SQL2005DE4:
SQL2005DE4:
关闭实例服务,类似启动实例服务,如:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati
