SQL Server database connection

Source: Internet
Author: User

1. If you want to query whether the connection is not released, you can use the query analyzer to connect to your database server and execute the following code:
Select * from Master. DBO. sysprocesses
Where spid> 50
And waittype = 0x0000
And waittime = 0
And status = 'sleeping'
And last_batch <dateadd (minute,-10, getdate ())
And login_time <dateadd (minute,-10, getdate ())
If there are many such processes, It means there are indeed many connections that have not been released (the above query shows that there have been no connections with any action for more than 10 minutes)
2. if the connection is not released, you can release the connection without changing the program. in SQL Server, create a job every 10 minutes. Execute the following code to regularly check and release the null connection:
Declare hcforeach cursor global
For
Select 'Kill '+ rtrim (spid) from Master. DBO. sysprocesses
Where spid> 50
And waittype = 0x0000
And waittime = 0
And status = 'sleeping'
And last_batch <dateadd (minute,-60, getdate ())
And login_time <dateadd (minute,-60, getdate ())
Exec sp_msforeach_worker '? '

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.