Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:31:36+00:00 2026-06-06T17:31:36+00:00

I ran this query in my database : SELECT DB_NAME(dbid) as DBName, COUNT(dbid) as

  • 0

I ran this query in my database :

SELECT  
DB_NAME(dbid) as DBName,  
COUNT(dbid) as NumberOfConnections, 
loginame as LoginName 
FROM 
    sys.sysprocesses 
WHERE  dbid > 0 
GROUP BY  dbid, loginame 

---------------------------------------------------
SELECT  COUNT(dbid) as TotalConnections 
FROM sys.sysprocesses 
WHERE  
dbid > 0 
---------------------------------------------------
exec sp_who2 'Active' 

I want to know the total number of connections to my database. The sum of first query and amount of second query are equal but the third query returns a different number of rows.

I want to know what the third query returns? I see some of the status’ in the result of the third query are sleeping. What does this mean? Is the connection idle, or it is ready in the pool? What does it mean if I have many sleeping connections in my result?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:31:38+00:00Added an answer on June 6, 2026 at 5:31 pm

    A status of sleeping means the session is connected but not actively running anything (e.g. the simplest definition, while perhaps not 100% accurate, is that there is nothing for that session_id in sys.dm_exec_requests).

    sp_who2 'active' filters out any spid that has a status of sleeping or has a last command of AWAITING COMMAND, LAZY WRITER or CHECKPOINT SLEEP. No I did not memorize what sp_who2 does; I simply looked at the source code:

    EXEC master..sp_helptext sp_who2;
    

    Note that sp_who2 is undocumented and unsupported, and sysprocesses is deprecated and currently present only for backward compatibility reasons. You will be better served, I think, with a procedure like Adam Machanic’s sp_whoisactive. Or at the very least knowing how to use the more modern DMVs like sys.dm_exec_sessions and sys.dm_exec_requests.

    EDIT

    I should add the unfortunate disclaimer that the more modern DMVs still don’t properly reveal the database(s) involved. But what does it really mean anyway? If you have a query like this:

    USE database_A;
    GO
    
    SELECT [column] FROM database_B.dbo.[table] 
      UNION ALL
    SELECT [column] FROM database_C.dbo.[table];
    

    What database id do you expect will get reflected in sys.sysprocesses.dbid for that session while this query is running? I’ll leave it as an exercise to the reader to determine what actually happens. Long story short, that’s not the view/column you want to rely on to know which databases are currently being “touched.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran a query against Northwind database Products Table like below select * from
I ran this sql query in my database: update payments set method = 'paysafecard'
I ran this query on my SQL Server database: begin transaction; insert into [db].[a].[Table1]
How can you get 1 as an output from #2? #1 I ran this
Ran into this error message while trying to select some records off a table.
I ran into a weird behavior from Oracle this morning... And I can't understand
Here's the query that is being executed on SQL Server 2008: SELECT "dbo"."tblMainData"."recID" FROM
In our production database, we ran the following pseudo-code SQL batch query running every
I have a query that gets comments from a database and displays them based
I ran this persons code. It worked as a main but when i put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.