How to view the number of data links in MS SQL Server series

Source: Internet
Author: User
Tags signal handler

"Go" how to view the current number of SQL Server database connections


1. Through the management tools
Start with management tools, performance (or run the inside input MMC) and then add a counter by adding the SQL statistics and then select the user connection in the items listed below to always query the number of connections to the database. However, this method needs to have access to the computer's permissions, that is, to log in through the Windows account to add this counter.

2. Querying through system tables

SQL Code

SELECT * FROM
[Master]. [dbo]. [sysprocesses] WHERE [DBID] In (SELECT
[DBID]
From
[Master]. [dbo]. [sysdatabases]
WHERE
Name= ' DBName '
)


DBName is the database that needs to be viewed, and then the number of rows queried is the current number of connections. But there are some other states that can be used for reference.

For example: Connect to master This database writes the following statement

SQL Code

SELECT * from sysprocesses where dbid in (select dbid fromsysdatabases where name= ' MyDatabase ')


The connection records for all connections MyDatabase This database are obtained.
sysprocesses This table records the connection to the SQL Server database.

3. Through the system's stored procedures to find

SQL Code

sp_who ' UserName '


Username is of course the user name of the login SQL, the general program will use a username to log in to the SQL so that the user name can be seen after the login of the connection.
If you do not write username, then all connections are returned.


SQL Code

sp_who ' sa '
SPID ecid status loginame hostname blk dbname cmd
------ ------ --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---
1 0 Background sa 0 NULL lazywriter
2 0 Background sa 0 Master SIGNAL HANDLER
3 0 sleeping sa 0 NULL 4/5/6/7/8 ...

(The number of rows affected is 15 rows)

How to view the number of data links in MS SQL Server series

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.