Returning Session Id (Integer) Number

Posted on 2005-05-02
Last Modified: 2010-03-19
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.
Question by:mubama0n
    LVL 11

    Expert Comment

    why would you want to do this?
    LVL 11

    Accepted Solution

    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
    LVL 34

    Expert Comment

    Of course, you wouldn't want to rely on the system tables for any of this information....

    Author Comment

    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.
    LVL 34

    Expert Comment

    I think if you explain more clearly what you're after, we can be more helpful.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now