How to view the current active connection of a database in real time

Source: Internet
Author: User
Data | database
Has been plagued by this problem, a few days ago on the Internet to find solutions. Now share the following:
Basic statement is sp_who
We can insert the query results into our own defined table (Monitoruser)
The base statement is
CREATE Table Monitoruser
(spid int,
ecid int,
Status varchar (200),
Loginame varchar (200),
Hostname varchar (200), \ \ New table structure based on sp_who results
Blk varchar (200),
dbname varchar (200),
CMD varchar (200),
[DateTime] [DateTime] Not NULL
)
ALTER TABLE [dbo]. [Monitoruser] With NOCHECK ADD
CONSTRAINT [DateTime] DEFAULT (getdate ()) For[datetime] \ Automatic fetch time to DateTime column
Go
Insert into Monitoruser (spid,ecid,status,loginame,hostname,blk,dbname,cmd)
EXEC (' sp_who ') \ Execute sp_who and insert the result into Monitoruser



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.