PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 21, 2022

[FIXED] How do you measure the number of open database connections

 April 21, 2022     asp.net, connection, database, sql     No comments   

Issue

I am trying to determine if I have a database connection leak. So I need to see the number of open connections. I have some simple test code that creates a leak:

protected void Page_Load(object sender, EventArgs e)
{
  for(int i = 0; i < 100; i++)
  {
    SqlConnection sql = new SqlConnection(@"Data Source=.\SQLExpress;UID=sa;PWD=fjg^%kls;Initial Catalog=ABC");
    sql.Open();
  }

}

Note there is no .Close and this does infact crash after being run 3 times in quick succession.

In order to measure the leak I am running the Performance monitor and measuring SQLServer: General Statistics/User Connections:

alt text
(source: yart.com.au)

However, these seem to be zero when I run my code:

alt text
(source: yart.com.au)

What should I change to actually see the connections?

ANSWER

I have approved an answer below. Even though it doesn't use the performance tools, its good enough for my use. Bottom line is I wanted to see how many connections remain open after opening a web page and this did the trick.


Solution

You can try running a query against the master db like this:

SELECT SPID,
       STATUS,
       PROGRAM_NAME,
       LOGINAME=RTRIM(LOGINAME),
       HOSTNAME,
       CMD
FROM  MASTER.DBO.SYSPROCESSES
WHERE DB_NAME(DBID) = 'TEST' AND DBID != 0 

See this link for more details.



Answered By - brendan
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing