Tracing

  • How do I trace a role(StoredProcExecuter) in sql server 2005 ? I am trying using the trace facility in sql profiler. I was wondering if there are any easier ways to do this. Basically I need to audit all the users and what they did on the role permissions(execute) .

    thanks

  • Do you want to trace all activity for a specific database role? Profiler/Trace does not provide a way to filter by role. You could trace all activity for a specific database and then use fn_trace_gettable to either load the trace file data to a table or to directly query the trace file and you can join to system views to determine what role each login was in. Check out this script[/url] for some ideas. To see database roles and users you would need to use sys.database_principals and sys.database_role_members

  • Yes exactly I want to trace the activity of a particular database role(StoredProcExecutor) .Audit everything for the past week . Who used it etc.I am looking for something easier other than the tracing option present in sqlprofiler.

    Thanks

  • Well, there might be a third party application out there that will do that, but SQL Server does not keep track of that as a role does not login a user does.

    Since it appears, by the role name, that it only has rights to execute stored procedures so why not put auditing code in the stored procedures. You could have a table with exec_date, exec_proc, exec_by and in you procedures you could put this code in your procedures:

    If IS_MEMBER('StoredProcExecutor')

    BEGIN

    INsert into AuditTable

    Select

    getdate(),

    'Procedure Name',

    SUSER_NAME()

    END

  • Thanks..But the issue is I would like to track the changes that have already been done . Not from now. Basically I want to track the past. Any thoughts .

    Thanks!

  • As I said in my first post, I don't think there is a way to do this outside profiler or the code I have suggested, and both of these would be from the point created forward, not the past. I don't even think a 3rd party log reader woul dhelp you because I don't think who did it is logged in the transaction log.

  • metro17 (12/15/2008)


    Thanks..But the issue is I would like to track the changes that have already been done .

    Can't be done.

    SQL doesn't keep track of that information unless you set up either triggers, a trace or similar. You can read the tran log (using fn_dblog or a 3rd party tool), but that will only get you changes and only back to the last tran log backup or checkpoint (depending on recovery model)

    I am looking for something easier other than the tracing option present in sqlprofiler.

    Then you'll be needing to buy a 3rd party tool.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • There is a default trace running in SQL 2005. Doubt you can get what you want out of there, but it's your only hope. Well, that or invent time travel.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • metro17 (12/11/2008)


    How do I trace a role(StoredProcExecuter) in sql server 2005 ? I am trying using the trace facility in sql profiler. I was wondering if there are any easier ways to do this. Basically I need to audit all the users and what they did on the role permissions(execute) .

    thanks

    use below script:

    IF EXISTS (SELECT 1 FROM sysobjects WHERE [name] = 'sp_Turn_Audit_On' AND type = 'P')

    DROP PROC sp_Turn_Audit_On

    GO

    CREATE proc sp_Turn_Audit_On

    as

    /************************************************** **/

    /* Created by: SQL Profiler */

    /* Date: 11/15/2006 05:16:40 PM */

    /************************************************** **/

    -- Create a Queue

    declare @rc int

    declare @TraceID int

    declare @maxfilesize bigint

    set @maxfilesize = 1024

    exec @rc = sp_trace_create @TraceID output, 2, N'E:Program FilesMicrosoft SQL ServerMSSQLTraceAudit_Info.trc', @maxfilesize, NULL

    if (@rc != 0) goto error

    -- Client side File and Table cannot be scripted

    -- Set the events

    declare @on bit

    set @on = 1

    begin

    exec sp_trace_setevent @TraceID, 14, 1, @on

    exec sp_trace_setevent @TraceID, 14, 6, @on

    exec sp_trace_setevent @TraceID, 14, 9, @on

    exec sp_trace_setevent @TraceID, 14, 10, @on

    exec sp_trace_setevent @TraceID, 14, 11, @on

    exec sp_trace_setevent @TraceID, 14, 12, @on

    exec sp_trace_setevent @TraceID, 14, 13, @on

    exec sp_trace_setevent @TraceID, 14, 14, @on

    exec sp_trace_setevent @TraceID, 14, 16, @on

    exec sp_trace_setevent @TraceID, 14, 17, @on

    exec sp_trace_setevent @TraceID, 14, 18, @on

    exec sp_trace_setevent @TraceID, 15, 1, @on

    exec sp_trace_setevent @TraceID, 15, 6, @on

    exec sp_trace_setevent @TraceID, 15, 9, @on

    exec sp_trace_setevent @TraceID, 15, 10, @on

    exec sp_trace_setevent @TraceID, 15, 11, @on

    exec sp_trace_setevent @TraceID, 15, 12, @on

    exec sp_trace_setevent @TraceID, 15, 13, @on

    exec sp_trace_setevent @TraceID, 15, 14, @on

    exec sp_trace_setevent @TraceID, 15, 16, @on

    exec sp_trace_setevent @TraceID, 15, 17, @on

    exec sp_trace_setevent @TraceID, 15, 18, @on

    exec sp_trace_setevent @TraceID, 20, 1, @on

    exec sp_trace_setevent @TraceID, 20, 6, @on

    exec sp_trace_setevent @TraceID, 20, 9, @on

    exec sp_trace_setevent @TraceID, 20, 10, @on

    exec sp_trace_setevent @TraceID, 20, 11, @on

    exec sp_trace_setevent @TraceID, 20, 12, @on

    exec sp_trace_setevent @TraceID, 20, 13, @on

    exec sp_trace_setevent @TraceID, 20, 14, @on

    exec sp_trace_setevent @TraceID, 20, 16, @on

    exec sp_trace_setevent @TraceID, 20, 17, @on

    exec sp_trace_setevent @TraceID, 20, 18, @on

    exec sp_trace_setevent @TraceID, 37, 1, @on

    exec sp_trace_setevent @TraceID, 37, 6, @on

    exec sp_trace_setevent @TraceID, 37, 9, @on

    exec sp_trace_setevent @TraceID, 37, 10, @on

    exec sp_trace_setevent @TraceID, 37, 11, @on

    exec sp_trace_setevent @TraceID, 37, 12, @on

    exec sp_trace_setevent @TraceID, 37, 13, @on

    exec sp_trace_setevent @TraceID, 37, 14, @on

    exec sp_trace_setevent @TraceID, 37, 16, @on

    exec sp_trace_setevent @TraceID, 37, 17, @on

    exec sp_trace_setevent @TraceID, 37, 18, @on

    exec sp_trace_setevent @TraceID, 46, 1, @on

    exec sp_trace_setevent @TraceID, 46, 6, @on

    exec sp_trace_setevent @TraceID, 46, 9, @on

    exec sp_trace_setevent @TraceID, 46, 10, @on

    exec sp_trace_setevent @TraceID, 46, 11, @on

    exec sp_trace_setevent @TraceID, 46, 12, @on

    exec sp_trace_setevent @TraceID, 46, 13, @on

    exec sp_trace_setevent @TraceID, 46, 14, @on

    exec sp_trace_setevent @TraceID, 46, 16, @on

    exec sp_trace_setevent @TraceID, 46, 17, @on

    exec sp_trace_setevent @TraceID, 46, 18, @on

    exec sp_trace_setevent @TraceID, 47, 1, @on

    exec sp_trace_setevent @TraceID, 47, 6, @on

    exec sp_trace_setevent @TraceID, 47, 9, @on

    exec sp_trace_setevent @TraceID, 47, 10, @on

    exec sp_trace_setevent @TraceID, 47, 11, @on

    exec sp_trace_setevent @TraceID, 47, 12, @on

    exec sp_trace_setevent @TraceID, 47, 13, @on

    exec sp_trace_setevent @TraceID, 47, 14, @on

    exec sp_trace_setevent @TraceID, 47, 16, @on

    exec sp_trace_setevent @TraceID, 47, 17, @on

    exec sp_trace_setevent @TraceID, 47, 18, @on

    exec sp_trace_setevent @TraceID, 104, 1, @on

    exec sp_trace_setevent @TraceID, 104, 6, @on

    exec sp_trace_setevent @TraceID, 104, 9, @on

    exec sp_trace_setevent @TraceID, 104, 10, @on

    exec sp_trace_setevent @TraceID, 104, 11, @on

    exec sp_trace_setevent @TraceID, 104, 12, @on

    exec sp_trace_setevent @TraceID, 104, 13, @on

    exec sp_trace_setevent @TraceID, 104, 14, @on

    exec sp_trace_setevent @TraceID, 104, 16, @on

    exec sp_trace_setevent @TraceID, 104, 17, @on

    exec sp_trace_setevent @TraceID, 104, 18, @on

    exec sp_trace_setevent @TraceID, 107, 1, @on

    exec sp_trace_setevent @TraceID, 107, 6, @on

    exec sp_trace_setevent @TraceID, 107, 9, @on

    exec sp_trace_setevent @TraceID, 107, 10, @on

    exec sp_trace_setevent @TraceID, 107, 11, @on

    exec sp_trace_setevent @TraceID, 107, 12, @on

    exec sp_trace_setevent @TraceID, 107, 13, @on

    exec sp_trace_setevent @TraceID, 107, 14, @on

    exec sp_trace_setevent @TraceID, 107, 16, @on

    exec sp_trace_setevent @TraceID, 107, 17, @on

    exec sp_trace_setevent @TraceID, 107, 18, @on

    exec sp_trace_setevent @TraceID, 109, 1, @on

    exec sp_trace_setevent @TraceID, 109, 6, @on

    exec sp_trace_setevent @TraceID, 109, 9, @on

    exec sp_trace_setevent @TraceID, 109, 10, @on

    exec sp_trace_setevent @TraceID, 109, 11, @on

    exec sp_trace_setevent @TraceID, 109, 12, @on

    exec sp_trace_setevent @TraceID, 109, 13, @on

    exec sp_trace_setevent @TraceID, 109, 14, @on

    exec sp_trace_setevent @TraceID, 109, 16, @on

    exec sp_trace_setevent @TraceID, 109, 17, @on

    exec sp_trace_setevent @TraceID, 109, 18, @on

    exec sp_trace_setevent @TraceID, 110, 1, @on

    exec sp_trace_setevent @TraceID, 110, 6, @on

    exec sp_trace_setevent @TraceID, 110, 9, @on

    exec sp_trace_setevent @TraceID, 110, 10, @on

    exec sp_trace_setevent @TraceID, 110, 11, @on

    exec sp_trace_setevent @TraceID, 110, 12, @on

    exec sp_trace_setevent @TraceID, 110, 13, @on

    exec sp_trace_setevent @TraceID, 110, 14, @on

    exec sp_trace_setevent @TraceID, 110, 16, @on

    exec sp_trace_setevent @TraceID, 110, 17, @on

    exec sp_trace_setevent @TraceID, 110, 18, @on

    exec sp_trace_setevent @TraceID, 115, 1, @on

    exec sp_trace_setevent @TraceID, 115, 6, @on

    exec sp_trace_setevent @TraceID, 115, 9, @on

    exec sp_trace_setevent @TraceID, 115, 10, @on

    exec sp_trace_setevent @TraceID, 115, 11, @on

    exec sp_trace_setevent @TraceID, 115, 12, @on

    exec sp_trace_setevent @TraceID, 115, 13, @on

    exec sp_trace_setevent @TraceID, 115, 14, @on

    exec sp_trace_setevent @TraceID, 115, 16, @on

    exec sp_trace_setevent @TraceID, 115, 17, @on

    exec sp_trace_setevent @TraceID, 115, 18, @on

    -- Set the Filters

    declare @intfilter int

    declare @bigintfilter bigint

    exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Profiler'

    -- Set the trace status to start

    exec sp_trace_setstatus @TraceID, 1

    -- display trace id for future references

    select TraceID=@TraceID

    goto noCursor

    error:

    select ErrorCode=@rc

    noCursor:

    return

    end

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply