| Author |
Topic |
|
okaasama
Starting Member
5 Posts |
Posted - 2008-07-15 : 18:34:37
|
Hi all, I hope someone can help me. I'm not a DBA, but have been researching sql trace and setfilter on and off for the past couple of months. I've run into a bit of a roadblock, and seek the wisdom of others! Thank you in advance for your valuable time.This is on MS SQL 2005, I think SP2.We're using a product, CA Audit, that set up a job to create trace files and load data from the trc files into a table, and a table to keep track of the files loaded.Most of the filters I've created are working fine, which are filtering on columns 34 and 35.Now I've been trying to filter based on the Permissions column, 19, but SQL gives errors when I run the sp with that.What I am trying to accomplish, is to NOT trace events with Permissions value of 1 (SELECT ALL).Here's the code - NOTE: I have obscured the columns being traced as well as the return fields except the 3 pertinent to this for security reasons, just to be extra safe.All of the setevents for each column being pulled have all of the same fields being returned.The sp is fed the 3 values requested, the first being the directory to put the file in, the second being 125 and the third being 1 2 or 3 typically.USE [IRECORDER]GO/****** Object: StoredProcedure [dbo].[dba_Trc_eTrust_Audit] Script Date: 07/15/2008 16:52:56 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER OFFGOALTER PROCEDURE [dbo].[dba_Trc_eTrust_Audit] @FileBase nvarchar(1000) , @Sec int , @TraceID int OUTPUT -- Return the TraceID to the caller. WITH RECOMPILE/** Creates a trace ***********************************************************************/AS -- Create a Queuedeclare @rc intdeclare @dbaTraceID intdeclare @maxfilesize bigintdeclare @DateTime datetimedeclare @TraceCount intDECLARE @FileName nvarchar(1000) , @StartDT datetime -- When the trace startedSELECT @StartDT = getdate()set @TraceCount = (SELECT COUNT(*) FROM dbo.dbaTrace WHERE FileLoadedDT is NULL)if (@TraceCount >= 10) BEGIN PRINT 'More Trace Files' goto finishENDset @maxfilesize = 50 SELECT @FileName = @FileBase + convert(varchar, @StartDT, 12) + replace(convert(varchar, GetDate(), 8), ':', '') , @DateTime = DATEADD (s, @Sec, @StartDT) set @maxfilesize = 50exec @rc = sp_trace_create @TraceID output, 2, @FileName, @maxfilesize, @DateTimeif (@rc != 0) goto error-- Client side File and Table cannot be scripted-- Set the eventsdeclare @on bitset @on = 1exec sp_trace_setevent @TraceID, x, y, @onexec sp_trace_setevent @TraceID, x, 19, @onexec sp_trace_setevent @TraceID, x, y, @onexec sp_trace_setevent @TraceID, x, 34, @onexec sp_trace_setevent @TraceID, x, 35, @onexec sp_trace_setevent @TraceID, x, y, @on-- Set up the trace filtersexec sp_trace_setfilter @TraceID, 19, 0, 1, N'1'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'SEOSDATA'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'dbaTrace'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'dbaTraceDetail'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'dbaTraceMissing'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'sp_trace_create'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'sp_trace_setstatus'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'sp_trace_setfilter'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'db_Trc_Load'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'db_Trc_LoadFile'exec sp_trace_setfilter @TraceID, 34, 0, 7, N'db_Trc_eTrust_Audit'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'IRECORDER'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'tempdb'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'msdb'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'master'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'mssqlsystemresource'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'ReportServer'exec sp_trace_setfilter @TraceID, 35, 0, 7, N'ReportServerTempDB'-- Set the trace status to startexec sp_trace_setstatus @TraceID, 1-- display trace id for future referencesEXEC @rc = dba_Trc_Record @FileName, @StartDT, @Sec , 'Scripted Trace for etrust Audit' , @TraceID, @dbaTraceID OUTPUTPRINT 'Recording Started. SQL Trace ID=' + CONVERT(varchar(9), @TraceID)PRINT 'dbaTrace.dbaTraceID = ' + CONVERT(varchar(9), @dbaTraceID)goto finisherror: select ErrorCode=@rcfinish: Without the line "exec sp_trace_setfilter @TraceID, 19, 0, 2, N'1'" the trace works fine.I know that for column 19, you can only use the comparison operators of = (1), <> (2), >= (4) or <= (5).I have tried it with all 4 of the operators.When using 4 and 5, I obviously did it with the number above it, so N'2'.For testing, I've tried to get it to both NOT capture permission of 1, and also TO capture permission of 1. Just for the sake of testing.For any of the variants I've tried in testing, if I manually execute it and fill in the values, I get back the following error:Msg 214, Level 16, State 3, Procedure sp_trace_setfilter, Line 1Procedure expects parameter '@value' of type 'bigint'.When it tries running on it's own through the job, it reports:Date 7/15/2008 11:51:55 AMLog Job History (eTrust_Audit_Job)Step ID 1Server (hostname obscured)Job Name eTrust_Audit_JobStep Name Create_TraceDuration 00:00:00Sql Severity 16Sql Message ID 214Operator EmailedOperator Net sentOperator PagedRetries Attempted 0MessageExecuted as user: NT AUTHORITY\SYSTEM. Procedure expects parameter '@value' of type 'bigint'. [SQLSTATE 42000] (Error 214). The step failed.What I don't understand is how the one trace line would cause that to happen.The only thing defined as bigint in the sp is "declare @maxfilesize bigint", which is being defined as 50 in the sp. That doesn't change any.... and there are less than 50 files in the directory.Any help, pointers, etc much appreciated!Regards,okaasama |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-15 : 18:42:18
|
Have you tried passing it as a number rather than a string?exec sp_trace_setfilter @TraceID, 19, 0, 1, 1From BOL:quote: [ @value = ] valueSpecifies the value on which to filter. The data type of value must match the data type of the column to be filtered. For example, if the filter is set on an Object ID column that is an int data type, value must be int. If value is nvarchar or varbinary, it can have a maximum length of 8000.
Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
okaasama
Starting Member
5 Posts |
Posted - 2008-07-15 : 19:15:34
|
Tara, thanks for the response!Unfortunately, it gave the same error. :(I welcome any other suggestions!Regards,okaasamaquote: Originally posted by tkizer Have you tried passing it as a number rather than a string?exec sp_trace_setfilter @TraceID, 19, 0, 1, 1
|
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-15 : 20:41:21
|
| That's weird. Here's my production code for SQL Trace: EXEC dbo.sp_trace_setfilter @traceId, 11, 0, 6, N'someuser' EXEC dbo.sp_trace_setfilter @traceId, 11, 1, 6, N'someotheruser' EXEC dbo.sp_trace_setfilter @traceId, 28, 0, 0, 20816As you can see, I'm filtering objectid 20816.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
okaasama
Starting Member
5 Posts |
Posted - 2008-07-16 : 10:15:44
|
| Please forgive my ignorance, but do I need to tell it that null values in column 19 are allowed?Hmmm, it's failing before that, isn't it... Is there any way I can do a debug or some such as the sp tries to run, where it does verbose logging or errors?Thanks,Samantha |
 |
|
|
okaasama
Starting Member
5 Posts |
Posted - 2008-07-16 : 10:56:49
|
Solved!!I changed it to the following and it worked!declare @bigintfilter bigintset @bigintfilter = 1exec sp_trace_setfilter @TraceID, 19, 0, 1, @bigintfilter So does anyone know why that is?? Why it couldn't just have the number itself? I still want to understand this.Thanks for putting me on the right path, Tara!Samantha |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-16 : 12:35:49
|
| I believe I ran into that issue too, but I didn't remember until I saw your last post. I believe it's because it doesn't know what data type you are passing and it demands that it be bigint.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
okaasama
Starting Member
5 Posts |
Posted - 2008-07-25 : 16:45:34
|
Oy vei!It still doesn't work.I have this in the trace:declare @bigintfilter bigintset @bigintfilter = 1 exec sp_trace_setfilter @TraceID, 19, 0, 4, @bigintfilter .... the sp runs fine, doesn't give an error, but it's not filtering out where Permissions is 1.I check this by looking at the events in the outside software, as well as by opening the traces it creates by profiler, and I can see clearly in the Permissions Column lots of entries with a value of 1.Any thoughts? The volume of the events is kinda pegging the server at times and we really need to get it figured out :(Thanks so much,Samantha |
 |
|
|
|
|
|