How to find the logins,program name and databases for a session id?

I used the following the following query.
select pr.spid ,pr.dbid,pr.program_name,pr.loginame,ss.session_id,ss.host_name,ss.login_time,db.name from master.dbo.sysprocesses pr,sys.dm_exec_sessions ss,sys.databases db
where pr.spid = ss.session_id and pr.dbid = db.database_id
order by ss.login_time desc
Is spid in master.dbo.sysprocesses the same as session_id in sys.dm_exec_sessions and dbid in master.dbo.sysprocesses the same as database_id in sys.databases?
My intention is to get the active sessions with the program name,login Name and database name corresponding to the session?

1)Why you included the clause session_id > 50?
Sessions with session_id <= 50 are system processes.
2)Is there any problem with the query I used?
You query was better than Latheesh's. To wit, his query will only show the database for sessions who are actually running something.
On SQL 2005 and SQL 2008, this is the best solution:
SELECT  des.session_id, des.[status], des.login_name,
        d.name AS database_name, des.program_name
FROM    sys.dm_exec_sessions des
JOIN    sys.sysprocesses p ON des.session_id = p.spid
LEFT JOIN sys.databases d ON p.dbid = d.database_id
WHERE   des.session_id > 50
  AND   p.ecid =0
ORDER BY des.session_id;
The condition p.ecid = 0 is needed to weed out extra rows when there are parallism in force.
On SQL 2012, you don't need sysprocesses, but this works:
SELECT  des.session_id, des.[status], des.login_name,
        d.name AS database_name, des.program_name
FROM    sys.dm_exec_sessions des
LEFT JOIN sys.databases d ON des.database_id = d.database_id
WHERE   des.session_id > 50
ORDER BY des.session_id;
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • How to find the file by name and identify its type?

    Hi,
    In a folder thare are many files, the file types are doc, docx, pdf, and rtf. The file name is something like "FirstName LastName(more extrat letters).filetype".
    Now I would like to find all the files with a certain name and identify their types. For example, by input "Bill Gates", I would get the list of all files :
    Bill Gates.doc, Bill Gates-2010.pdf etc ...
    Any good ideas are welcome.
    Pengyou

    For finding files whose names match a certain pattern, create a FileFilter or FilenameFilter that returns true when the name matches the pattern in question, and then call list() or listFiles() with that filter.
    For identifying the "type", that depends what you mean. File's don't actually have a type. It's just that they're interpreted as such in some contexts. The simplest thing is to just look at the extension. You can be more sophisticated than that, but that gets complicated real fast. It depends what you're actually trying to accomplish.

  • How to find the current User Name and stored in which table

    In which table the current user name (Login) is stored?

    Hi Mohanapriya
    The query provided by Gordon can not run on query generator as the $USER is a runtime variable.
    You need to save it to a query then use it in a FMS(Formatted Search.)
    Just open a form(ex:sales order ), click the field in which you want to show the user name,
    then press ****+F2 or Tools->Search Function->Define,
    Search by Saved query,then assign the save query to the field.
    After that ,you can run the FMS(shift+F2) to get the current user info.
    Regards,
    Syn Qin
    SAP Business One Forums Team

  • How do I find the report server name, and then run paper report from forms?

    How do I find the report server name, and then run paper report from forms?
    I am having a problem running report 9i from forms 9i (see below thread). How do I find out the name of the report server? I checked my C:\ids\reports\conf directory but don't see anything that gives me the name of the reports server. I also don't have a iashome directory.
    Also, I just want to run the paper report (not the web version).
    Thanks.

    Hi,
    please read teh Forms / Reports integration paper in teh Collateral section for Oracle9i Forms at otn.oracle.com/products/forms
    In summary, you have to create an external Reports Service that you can then give a name.
    Frank

  • How can I find the specific channel name and modify channel name in automatically in VBS?

    How can I find the specific channel name and modify channel name in automatically in VBS? (DIAdem 9.1)
    I would like to change channel name = "speed01" ... "speed10"  to  channel name = "velocity01"..."velocity10.
    martino

    Hello Martino,
    this script will help:
    Option Explicit
    Dim i
    Dim n
    For i=1 To 10
    If i < 10 then
    n = CNo("speed0" & i)
    Else
    n = CNo("speed" & i)
    End If
    If n > 0 Then
    If i < 10 then
    ChnName(n) = "velocitiy0" & i
    Else
    ChnName(n) = "velocitiy" & i
    End If
    End If
    Next
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • How to find PG.xml file name and path associated with a FUNCTION

    Hi,
    I am having a function:IRC_VIS_HOME_PAGE with Web HTML value as below:
    OA.jsp?akRegionCode=IRC_VIS_HOME_PAGE&akRegionApplicationId=800&OAPB=IRC_BRAND
    How to find PG.xml file name and path assoicated with above funtion.
    Thanks,
    ashok

    Ashok,
    Function IRC_VIS_HOME_PAGE will have 2 parameter defined for it which are OASF and OAHP where
    OASF=<SelectedFunctionName> - this tells the Framework to select this function in the given "Home Page" menu context.
    OAHP=<HomePageMenuName> - this is used ONLY with the OASF parameter, and it is used to establish the current menu context. It should point to a "Home Page" menu.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to find the outbound program for standard IDoc

    Hi Folks,
    Can anyone tell me how to find the outbound program/tcode for a standard IDoc? For e.g. IDoc - MATMAS05 can be generated & distributed using tcode BD10. Similarly how do I find the outbound program/tcode for any standard IDoc? Is there any procedure to find the same.
    I have tried to search based on the package name, but unfortunately I didn't find the information for IDoc: COND_A04.
    Thanks in advance.
    Somu

    You can do following steps if the idoc is generated based on change pointer concept (for masters)
    - Identify the message type associated with idoc type (table EDIMSG).
    - Function module for generating the IDOC will be available in table TBDME (pass message type as input).
    Refer to the standard Outbound IDOC generation program RBDMIDOC for more details.
    If the idoc is generated based on the process code concept (transaction data), get the process code information from table TMSG1 (pass message type as input), get the function module associated process code from table TEDE1 (pass process code as input).
    Regards, Vinod
    P.S: There is no standard way to find out the associated program / Tcode for generating idoc. The above process will be helpful to find out the underlying function modules to generate the idoc.  For generating idocs based on change pointers the generic program RBDMIDOC can be used.
    Edited by: Vinod Kumar on Jul 13, 2011 2:15 PM

  • How to find the Standard DFF Name  In oracle apps

    hi,
    How to find the Standard DFF Name In oracle apps
    thanks

    1. Open the form
    2. Choose Tools--> Diagnostics
    3. In the block field choose $DESCRIPTIVE_FLEXFIELD$
    4. Field will show the list of all the DFF's enabled for that form.
    5. Choosing one will display the name of the DFF in the value field.
    Thanks
    Nagamohan

  • How to find the Last modified date and time of a package

    Hi,
    We need a clarification on how to find the Last modified date and time of a package in Oracle. We used the example below to explain our scenario,
    Lets consider the following example
    Let A, B be two packages.
    Package A calls the package B. So A is dependent on B.
    When A is compiled the TIMESTAMP,LAST_DDL_TIME in USER_OBJECTS gets updated.
    Now there a modification in package B so it is compiled. There is no modification in package A.
    Now when the package A is executed the TIMESTAMP,LAST_DDL_TIME in USER_OBJECTS gets updated but we did not make any change in Package A. Now we need to find last modified date and time of the package A . So we can not rely on the TIMESTAMP,LAST_DDL_TIME in USER_OBJECTS . Can u please tell us any other solution to get last modified date and time of the package A .
    Regards,
    Vijayanand.C

    Here is an example:
    SQL> SELECT OBJECT_NAME,CREATED,LAST_DDL_TIME,TIMESTAMP,STATUS FROM USER_OBJECTS
    2 WHERE OBJECT_NAME = ANY('A','B');
    OBJECT_NAM CREATED LAST_DDL_TIME TIMESTAMP STATUS
    A 20-MAY-2004 10:57:32 20-MAY-2004 10:57:32 2004-05-20:10:57:32 VALID
    B 20-MAY-2004 10:58:22 20-MAY-2004 10:59:04 2004-05-20:10:59:04 VALID
    SQL> CREATE OR REPLACE PROCEDURE A AS
    2 BEGIN
    3 NULL;
    4 NULL;
    5 END;
    6 /
    Procedure created.
    SQL> SELECT OBJECT_NAME,CREATED,LAST_DDL_TIME,TIMESTAMP,STATUS FROM USER_OBJECTS
    2 WHERE OBJECT_NAME = ANY('A','B');
    OBJECT_NAM CREATED LAST_DDL_TIME TIMESTAMP STATUS
    A 20-MAY-2004 10:57:32 20-MAY-2004 11:01:28 2004-05-20:11:01:28 VALID
    B 20-MAY-2004 10:58:22 20-MAY-2004 10:59:04 2004-05-20:10:59:04 INVALID
    SQL> EXEC B
    PL/SQL procedure successfully completed.
    SQL> SELECT OBJECT_NAME,CREATED,LAST_DDL_TIME,TIMESTAMP,STATUS FROM USER_OBJECTS
    2 WHERE OBJECT_NAME = ANY('A','B');
    OBJECT_NAM CREATED LAST_DDL_TIME TIMESTAMP STATUS
    A 20-MAY-2004 10:57:32 20-MAY-2004 11:01:28 2004-05-20:11:01:28 VALID
    B 20-MAY-2004 10:58:22 20-MAY-2004 11:01:53 2004-05-20:11:01:53 VALID
    Note that the date under the column 'created' only changes when you really create or replace the procedure.
    Hence you can use the column 'created' of 'user_objects'.

  • How to find the print program for a sap script

    Hey Experts,
    How to find the print program for a sap script (espicially when it is a custom script(Z*))?
    Thanks a ton,

    Thanx Vijay,
    Actually when I searched for the program in both the tables it didnt show up ther.
    But when I did check in the texts of script, I found it.
    Good job.
    Thanks all.
    Vijay, a small doubt.
    But why didn't it show up in those 2 tables when all the print programs for standard scripts show up usually?
    thnx once again.
    Message was edited by: dev a

  • How to find the relation between PAY_ELEMENT_TYPES_F and GL_CODE_COMBINATIO

    Hi, could someone tell me how to find the relation between PAY_ELEMENT_TYPES_F and GL_CODE_COMBINATION tables
    that is because as you could know PAY_ELEMENT_TYPES_F holds the definitions of elements in Oracle HRMS and i need to find the accounting code of each element.
    Thanks

    Hi;
    Please check e-trm site for table relation,integration,explanation etc..
    etrm.oracle.com/
    Regard
    Helios

  • How to get the field row name of database from a form?

    Hello experts,
    I am newer in OIM and developments with the API's.
    I have this environment,
    one resource that have the attribute department
    relationship with the database row
    UD_RESOURCE1_DEPARTMENT and other resource with the same attribute in, UD_RESOURCE2_DEPARTMENT
    I am programing one java class that put values in the
    form field through the table name, sample,
    UD_RESOURCE_DEPARTMENT.
    I let some code:
    # Hash table with the value of Department
    myMap.put("UD_RESOURCE_DEPARTMENT", value);
    # and save in the resource form
    tcFormInstanceOperationsIntf tcform = (tcFormInstanceOperationsIntf)tcUtilityFactory.getUtility(dataProvider,"Thor.API.Operations.tcFormInstanceOperationsIntf");
    tcform.setProcessFormData(Long.parseLong(formKey), myMap);
    But this solution implies know the name of the field in the database and not is a global solution.
    I am interesting in know how I can obtain the name of the
    row field of the database for the atribute. Does anybody know how to obtain the row field name of database from an IT Resource or through the field name of the form?
    Is this the correct way to store data in a form?
    Thanks in advanced.

    Hi,
    Thank you.
    I have seen this function in the OTN help, but how can i get the index number. My requirment is when saving the data, I need to save both the value and the element name into the database,
    Also it is tabular block, more than one rows
    Thanks again

  • Anyone knows how to find the mac-adress on an Ipad(for network)

    anyone knows how to find the mac-adress on an Ipad(for network connection)

    chose settings - general- about...and there it is  , the wi-fi-adress :-)

  • How to find out exact labour hour and expenses for each labour attached to

    Team,
    How to find out exact labour hour and expenses for each labour attached to machine
    We are planning to go with CATS.
    But in Cats how Production Planning department get the exact labour coust
    (which includes labour accomodation building , EB etc. paying by comp)
    How to do this in CATS
    REX

    hai
    generally  the schemas are named X000  which stands for common schema  nomination
    x replaced by respective country like for india it is IN00  for US  U000etc
    it is not given according to the group of emplyees but according to the country grouping for your org units
    time schemas are country independent they work for all the countries
    regards
    nalla

  • How to find the structure fields data in database tables?

    how to find the structure fields data in database tables?

    Your question doesn't appear to be Web Dynpro ABAP related. Please only post questions in this forum if they are directly Web Dynpro ABAP related.  There are several other more general ABAP related forums.

Maybe you are looking for