• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Returning Session Id (Integer) Number

Hi , If more than 1 user try to access any table for (select or delete or insert or update) how I can get by SQl query the session id (Integer) number e.g.: Session Id 1 for user x , session id 2 for user y,...etc.
1 Solution
why would you want to do this?
Craig YellickDatabase ArchitectCommented:
If by session ID you mean a web server application session, there is no correlation maintained by SQL Server between user connections and the underlying application session.

You might find the SQL Profiler to be very useful, it will capture activity from one or more (or all) users. From there you can see who is using which tables etc.  Not quite as clean as a direct listing of concurrent activity, but depending on what you're trying to accomplish it might be just what you need.

If you're keen to see exactly which database objects are being used by each connected user, start by manually examining the Current Activity listings in SQL Enterprise Manager (SEM).  You'll find them in the Management folder.  Start with the Process Info listing, you'll see the user names and server process ID (spid).  The spid is the key to correlating users with the objects they have locked.

These listings in SEM are based on queries against system tables. You can issue these queries yourself and apply filters, though the relationships are complex. To get started, examime the following (all are found in the master database).

     select * from syslocks
     select * from syslockinfo

-- Craig Yellick
Of course, you wouldn't want to rely on the system tables for any of this information....
mubama0nAuthor Commented:
Mr lluthien

 Based on the Session Id I'll do some inquery process , if you have more information please add your comment.

CraigYellick thanks for this illustration if no one add comments within one day I'll accept your recommendations.
I think if you explain more clearly what you're after, we can be more helpful.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now