"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