How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"

How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"?
I have an install SQL scripts that creates a Linked Server. I want to put some security on the Linked Server and only grant the Agent Job Signon (the "Run As" or "Executed as User") access to the linked server. I need to retrieve the
Agent Job Signon (something like "NT SERVICE\SQLAgent$FIDEV360BI02").
I could query certain jobs and SUBSTRING the Message column - using some form of the query below, which would return "Executed as user: NT SERVICE\SQLAgent$SSDEVBI02. The step succeeded." But that is pretty imprecise.
use msdb
SELECT [JobName] = JOB.name,
[Step] = HIST.step_id,
[StepName] = HIST.step_name,
[Message] = HIST.message,
[Status] = CASE WHEN HIST.run_status = 0 THEN 'Failed'
WHEN HIST.run_status = 1 THEN 'Succeeded'
WHEN HIST.run_status = 2 THEN 'Retry'
WHEN HIST.run_status = 3 THEN 'Canceled'
END,
[RunDate] = HIST.run_date,
[RunTime] = HIST.run_time,
[Duration] = HIST.run_duration,
[Retries] = HIST.retries_attempted
FROM sysjobs JOB
INNER JOIN sysjobhistory HIST ON HIST.job_id = JOB.job_id
-- CHANGE THIS
-- WHERE JOB.name like '%GroupMaster%' or Job.name like '%etlv%'
ORDER BY HIST.run_date, HIST.run_time

by default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
so, if it is null, it ran as sql server agent account.
so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
accurate information as the new account will show up though the job really ran as old account, to get this information, you need to  get this from the logmessage column as you mentioned above.
 try this code...
/*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
declare @sqlserveragentaccount varchar(2000)
select @sqlserveragentaccount= service_account
from sys.dm_server_services
where servicename like '%sql%server%agent%'
select message,isnull(name,@sqlserveragentaccount) as AccountName
from sysjobhistory a inner join sysjobsteps b
on a.step_id=b.step_id and a.job_id=b.job_id
left outer join sysproxies c on c.proxy_id=b.proxy_id
Hope it Helps!!

Similar Messages

  • How to get a SQL statement that trigerred a trigger ?

    I'd like to trace all insert and update operations done on a table.
    So, how can I get the SQL statement that triggered a trigger ?
    Thanks

    Use AUDIT to trace all sql statement about table, views etc. (except column) :
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_4007.htm#SQLRF01107
    Or, if you are in 9i or later, you can use DBMS_FGA (you can audit just a column) :
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10802/d_fga.htm#ARPLS015
    Nicolas.

  • HT2602 I am stuck. I can not figure out how to get the microsoft office that is on my (admin) profile dock onto the dock for the other users on my mac. Can anyone help me out?

    I am stuck. I can not figure out how to get the microsoft office that is on my (admin) profile dock onto the dock for the other users on my mac. Can anyone help me out?

    ebony --
    So, when you open your main Applications folder, there is no Office app there?
    It's in your Users>Applications folder?

  • How to get the current request id in a running request?

    How to get the current request id in a running request?
    Thanks.

    Did you notice that there's a whole section on this forum dedicated to this topic, called E-Business Suite?
    C.

  • Urgent:How to get the Sqltext for Oracle Sumbitted Jobs in 10g

    Dear All,
    Could you help me out in sorting the below problem.
    I use to get the current running sql's with following below query in 9i.
    SELECT A.SID,B.HASH_VALUE, OSUSER, USERNAME, SQL_TEXT
    FROM V$SESSION A, V$SQLTEXT B
    WHERE B.HASH_VALUE = A.SQL_HASH_VALUE
    AND USERNAME LIKE upper('%SCHEMA%')
    ORDER BY B.HASH_VALUE, B.PIECE;
    This is will work in 10g also for user-triggered sqls,stored procedures etc.
    But when oracle submits job i'm not able find which qurery is running.
    Seems For oracle jobs in 10g for V$session contain column SQL_HASH_VALUE as Zero and hence i'm not able find the any sql's running.
    Could you please any of you help me out how to get the Sqltext for Orcle submited Jobs in 10g.
    Please revert asap as this is very urgent for me.
    Thanks in Advance
    Anil.

    Have you tried to query WF_ITEMS? -- http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=WF_ITEMS&c_owner=APPLSYS&c_type=TABLE
    bde_wf_item.sql - Runtime Data of a Single Workflow Item [ID 187071.1]
    Thanks,
    Hussein

  • How to get the Sql inside Omni SQL portlet.

    Hi,
    We are trying to find a table/view which stores/holds the Sql and Pl/Sql code of Omni Pl/sql portlets.
    Thanks,
    Ram.

    by default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
    you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
    so, if it is null, it ran as sql server agent account.
    so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
    accurate information as the new account will show up though the job really ran as old account, to get this information, you need to  get this from the logmessage column as you mentioned above.
     try this code...
    /*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
    declare @sqlserveragentaccount varchar(2000)
    select @sqlserveragentaccount= service_account
    from sys.dm_server_services
    where servicename like '%sql%server%agent%'
    select message,isnull(name,@sqlserveragentaccount) as AccountName
    from sysjobhistory a inner join sysjobsteps b
    on a.step_id=b.step_id and a.job_id=b.job_id
    left outer join sysproxies c on c.proxy_id=b.proxy_id
    Hope it Helps!!

  • I tunes has stopped working in windows 7 and I don't know how to get the crash information that everyone else seems to get to know what the cause is....any help?  I have a toshiba windows 7 computer.

    I have a toshiba computer and it is windows 7, recently after I installed imatch everytime I open itunes I get the message 'i tunes has stopped working' and windows cannot find a solution and has to close.  There is no solution and I don't know how to get the crash information on my computer....can anyone help as I want to finish downloading all my songs to match to be available on my mac products.

    Re: That garbage is unreadable.
    If you really want help, stop messing with the fonts and post so that others can read and offer suggestions.
    Or better yet... try a search, I'm certain you'll find a solution to whatever issue you're experiencing.
    I have found that many times it is the things that make you most angry that push you to action. This was the case here. Thank you for causing me to get so angry that I found the answer myself.

  • How to get the SQL file name in SQL*plus

    hi all,
         I have created two sql file at C drive as "c:\Createtable.sql" and "c:\Deletetable.sql"
    afterwards i open
    C:\>sqlplus
    SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jan 30 11:37:10 2008
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Enter user-name: scott/tiger
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> @C:\Createtable.sql'
    Table created.
    SQL> @'C:\Deletetable.sql'
    Table dropped.
    SQL>My problem is to get the name of the file as "c:\createtable.sql" and "C:\Deletetable.sql" in sql*plus enviornment.
    Thanks & Regards
    Singh

    Dear Damorgan,
         >>your version number to three decimal places
         My Oracle DB Version i have already stated in my previous post is 10.2.0.1.0
    Actually my problem is to get the sql files name we run in sqlplus enviornment with @ symbol. like
    i have created one sql file in c drive as
    "C:\Createtable.sql"
    afterwords i have connected to sqlplus as
    sql> conn scott/tiger
    sql>@c:\createtable.sql
    Now i want some query to get the name of the file which is run.
    In actual my problem is as
    i have suppose 10 or more SQL files in some folder ( sql1.sql, sql2.sql, sql3.sql ....).
    i created one file to call all the 10 sql files (main.sql)
    i have also one track_table which will keep track that which sql file is runned.
    I want some automated script which will insert the record in that track_table....... for that i need the name of sql file which is runned.
    Hope this will help you.
    Thanks & Regards
    Singh

  • AI CS3 Plugin: How to get the file format that is selected in the "save as" dialog??

    Hi,
    Someone please help me in getting the file format that is selected in the "save as" dialog. I wanted to retrieve it in the string format.
    I tried sAIDocument->GetDocumentFileFormat. But i'm unable to implement it correctly. Is there a better way or How do I implement this? Precisely, I wanna get the value as a string when the user selects "save as .pdf".

    Do you really need to know the file type? What about just checking the bit depth?
    var doc = activeDocument;
    if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) {//Not 8 bit
    doc.bitsPerChannel = BitsPerChannelType.EIGHT;
    //do your save etc
    }else{
        //Ignore

  • How to get the SQL queries based on SQL_ID.

    Hi Experts,
    I want to get the SQL queries based on SQL_ID.
    I have tried the following query,but I am not getting full query.
    [code]SET linesize 132 pagesize 999
    column sql_fulltext format a60 word_wrap
    break on sql_text skip 1
    SELECT   REPLACE (TRANSLATE (sql_text, '0123456789', '999999999'), '9', ''),sql_id
    FROM   dba_hist_sqltext s
    WHERE   s.sql_id = '7tvurftg8zryb';[/code]
    One of my friend said use grid to get full query text.
    Can you please help me how to use grid ,else any other method to get the full query based on SQL_ID.
    Please help me.
    Thanks in advance.

    You have these many options to set, if sql_text is really huge. But better use a tool(TOAD) as it's really helpful and easy to use instead! (See my previous comment).
    column sql_text format A10000
    set echo off
    set head off
    set feed off
    set verify off
    set termout off
    set lines 10000
    set long 1000000
    set trimspool on
    set pages 0
    Thanks!

  • How to get the SQL statement

    I cannot figure how to get the text(SQL statement) from a system view(i guess it is in a system view... but witch??). 'Till now i have the sql_address and the sql_hash_value..
    I know it is possible.. EM does it ... so i should be able to do the same..
    ps:I use 9.2

    v$sql ?

  • When I purchased a music app from itune store. This got downloaded in Itune maedia/Mobile applications.How to get the songs in that app to my  itune library or on to IPAD?

    I  or tranfer to my librarypurchased from Itune store a Music app. It is downloaded into intune media/mobile applications. How to get the full album msic/songs into my itunes library or on tomy IPAD? It doesnot open out. Can anybody suggest a way?

    If you have a music downloader app (depends on which you have), plug your iDevice into iTunes, go to your device (on itunes), go to your apps, scroll down, and select the app thats holding your music, click on "Save As" (should be located bottom right corner), save the music to your specific folder. Once done, follow through this: Adding music and other content to iTunes and you should have your music on your iDevice music app.
    Hope this helps.

  • How to get the SQL Execution Plan from complex Extractors ?

    Hi
    I am looking for a way to get  the
    SQL Execution Plan(s!) 
    from
    Complex Extractors like 0CO_OM_CCA_9 ?
    Anybody has got a suggestion ?
    How to get this in SM50 ?
    ThanXs
    Martin

    Identifying the query is the hard part. If you can identify it(based on table access or some such parameter, getting the execution plan is easy in ST04 .

  • How to get the spool information for a job

    Hi,
    After a job is run, how to get the spool inforamtion. which API can be used.?
    Thanks in advance.
    Johnney.

    Hi,
    thanks for your reply.
    My requirement is as followings.
    1. Report Z_REPORT_TEST
    EXPORT RUNUUID = '****************' TO MEMORY ID sy-repid.
    2. In Funciton Module Z_FM_test
                create a job(Z_JOB_TEST) to run report 'Z_REPORT_TEST'.
                after the job is run successfully.
                question is
                how to get the RUNUUID exported from the report ????
    Thanks & Best Regards,
    Johnney.

  • How to get the trace file name for current running application?

    Hi, I want to know if it is possible to get the file name directly for current running application instance which is launched by javaws.
    There is a property "deployment.user.logdir" tells the log directory, it would be great if a file name property
    is available. something like "instance.trace.file".
    Our application wants it because we would like our client send use the application log by clicking a "send error"
    button, the codes finds the trace file and compress it and send it by using a smtp server.
    In 1.5, we can do it by using a shell program.

    I found other asked it before, but I tried to set both properties, but neither works. my sun JRE version :java version "1.6.0_04"
    <property
    name="deployment.javaws.traceFileName"
    value="abcfefsfdsf"/>
    <property
    name="deployment.javapi.trace.filename"
    value="235235235"/>
    But it always write to one trace file with name lik javaws63645.trace

Maybe you are looking for