How can you know which table caused a clr trigger to fire ?

  • Hello great Helpers,

    written a c# trigger, got it running and it appears to work as expected.

    It keeps track of a changelog.

    It is allmost written independent of the table for which it has been written.

    The only statement that is dependent is the TableName - that should appear in the changelog.

    Looking around, I saw code to get that TableName like:

    SqlCommand cmd = new SqlCommand("SELECT object_name(resource_associated_entity_id) FROM sys.dm_tran_locks WHERE request_session_id = @@spid and resource_type = 'OBJECT'", conn);

    I tried this, but it appears not to work as generic as I would like.

    Who has the generic clue ?

    Thank you in advance,

    Edmond de Savornin Lohman

    Utrecht, Netherlands

  • I'm not sure how you created the trigger.

    But within the trigger you can use the @@PROCID.

    That will give you the obejct_id of the trigger. From there you can track back the base table name for the trigger using the system views.

Viewing 2 posts - 1 through 2 (of 2 total)

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