I have a table that has a Trigger associated with it for Update, Insert and Delete. The Trigger works fine and executes. Here is the code for my trigger:
CREATE trigger [dbo].[trg_audit_TableName]
ON [dbo].viewLayers
FOR INSERT, UPDATE, DELETE
AS
SET NOCOUNT ON
declare @inputbuffer table (EventType nvarchar(30),Parameters int,EventInfo nvarchar(4000))
insert into @inputbuffer exec('dbcc inputbuffer('+@@Spid+')')
declare @ins int
declare @del int
select @ins = count(*) from inserted
select @del = count(*) from deleted
insert into audit_TableName (eventtime, CurrentMachine, appName, CurrentUser, eventtype, tsql)
select getdate(), host_name(), APP_NAME(), suser_sname(),
case
when isnull(@ins, 0) > 0 and isnull(@del, 0) > 0 then 'update'
when isnull(@ins, 0) > 0 and isnull(@del, 0) = 0 then 'insert'
else 'delete'
end,
EventInfo
from @inputbuffer
Now, if I run a stored procedure from the Management Studio, the TSWL data inserted into the table looks like this:
sp_TestInsert 'paramdata 1', 'paramdata 2'
But, if I run the procedure from my .NET appliation using an SQLCommand object, the TSQL field doesn't show the parameters:
sp_TestInsert;1
If I open up the profiler for this stored procedure when it is executed from .NET this is what I see:
exec sp_TestInsert @val1='paramdata 1',@val2='paramdata 2'
Yet, the audit table still shows
sp_TestInsert;1
Is there a way that I can retrieve the parameters passed with the Stored Procedure?
EDIT: Depending on the stored procedure, it will insert / update / delete data in a table that has the trigger
EDIT 2: Here's a very brief example of the .NET Execution ('conn' is my SQLConnection object):
Using cmd As SqlCommand = conn.CreateCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sp_TestInsert"
cmd.Parameters.AddWithValue("@val1", "paramdata 1")
cmd.Parameters.AddWithValue("@val2", "paramdata 2")
cmd.ExecuteNonQuery()
End Using