Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 525587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:41:14+00:00 2026-05-13T08:41:14+00:00

I have a table that has a Trigger associated with it for Update, Insert

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:41:15+00:00Added an answer on May 13, 2026 at 8:41 am

    I ended up modifying the trigger to also include the inserted / deleted data like so:

     declare @insData varchar(max)  
     set @insData = (select * from inserted for xml auto)  
     declare @delData varchar(max)  
     set @delData = (select * from deleted for xml auto)  
    

    And then inserted @insData and @delData into the audit table. This now shows what was changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 296k
  • Answers 296k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer var divElem = $("#yourdivid"); var ht = divElem.height(); var wdt… May 13, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer This would happen if you have a slow internet connection,… May 13, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer A solution to embed an image directly in an HTML… May 13, 2026 at 7:08 pm

Related Questions

A little presentation for what I want to do: Consider the case where different
I am currently working on a particularly complex use-case. Simplifying below :) First, a
Ok, so my schema is this: Table: Timesheet_Hours Columns: Timesheet_Id (PK, int) Staff_Id (int)
Consider the Following object model (->> indicates collection): Customer->Orders Orders->>OrderLineItems->Product{Price} The app is focused
I am working on a ASP.NET MVC website using Nhibernate as my ORM. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.