Q: Is there a way to se the amount of active sql connections.

  • Thread starter Martin Arvidsson, Visual Systems AB
  • Start date
M

Martin Arvidsson, Visual Systems AB

Hi!

I am developing an application, and i suspect i am forgetting to close a
connection.

Is there a way to se how many connections that are active to the sql server?

Studio 2008 and SQL Server 2005 Developer is used.

Regards
Martin
 
M

Marc Gravell

sp_who or a performance counter are simple ways.

Just note that unless you have disabled connection pooling, it is likely
that when you Close() and Dispose() a SqlConnection (or whatever), that
it actually still remains connected to the SQL Server (i.e. has a spid)
- the reason being that it is kept in the pool for re-use. As long as
this number doesn't keep growing, it is generally fine.

Marc
 
M

Marc Gravell

And re forgetting to close; try "using" the connection - then you can't
forget:

using(SqlConnection conn = new SqlConnection("..."))
{
conn.Open();
// etc
}

Even if an exception happens, the exception should still be released (to
the pool) correctly.

Marc
 
C

christery

Is there a way to se how many connections that are active to the sql server?

Should be visible in the SQL server, at least I can check that in
Oracle... clients I mean.. (one or several from one client are treated
as different connections)

//CY
 
M

Marc Gravell

I am developing an application, and i suspect i am forgetting to close a
sp_who active

If the problem is that they haven't been closed, then chances are that
they are actually idle - in which case just "sp_who" is probably a safer
bet...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top