Querying the number of SQL Server database connections and disconnecting

Source: Internet
Author: User
Tags session id

A production environment, a line of the environment, the online environment of the data problems in the production environment does not appear, so you need to restore the line database to the production environment, but every time the restoration of the resignation database is in use, can not be restored, but the naked eye is not visible, So you need to query out the database connection and force the disconnection.

1. Query the maximum number of users that SQL Server allows simultaneous connections

SELECT @ @MAX_CONNECTIONS

2. Querying the current connection information for the specified database

SELECT *  from WHERE inch (   SELECT from master.dbo.sysdatabases   WHERE NAME=  'yourdatabasename'-- The specified database name )

Or

SELECT *  from WHERE db_name = ' YourDatabaseName '

The meanings of each field in table master.dbo.sysprocesses see http://www.cnblogs.com/buaaboyi/archive/2010/04/06/1705142.html

3. Force shutdown of database connections in SQL Server

Kill  Wu -- 54 is the SPID, which is the  SQL Server session ID.

Querying the number of SQL Server database connections and disconnecting

Related Article

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.