sql server tempdb trigger not firing based on user/process

Hi -
I have a AFTER INSERT/UPDATE trigger on a table in TempDB (to be explained further down)
which does not fire/execute when a record is inserted or updated from "applications".

However, when I go into SSMS and update a record I can watch it execute in a profiler trace without error.

Is there any obvious reason for this I am overlooking ?
Google has not been my friend so far on this search....

This is a local application running SQLEXPRESS and using tempdb for speed due to many, many singluar and batch INSERTS.

I tried/and thought maybe something to do with creating the trigger "with execute as owner" but that does not seem to be the issue.

Additionally - the trigger is doing an INSERT/UPDATE into a table in another database (same instance) - again, this works fine if I execute it in SSMS.

In this scenario - I happen to be logged into SSMS and the database as domain\administrator - and the application is running as that user as well.
My assumption being, for testing - that indeed both processes are running as same user, eliminating permissions as the reason....
Who is Participating?
Scott PletcherConnect With a Mentor Senior DBACommented:
What about my earlier comment??:

"Also, certain types of statements may not fire triggers, such as BULK INSERTs.  Verify that your app isn't using that type of statement."

That was EXACTLY what it was, right?
Scott PletcherSenior DBACommented:
Have you verified that the trigger is really not firing?

Such as put a non-conditioned INSERT to a dummy/trace as the *first* thing in the trigger to see if the trigger was entered.

Maybe there is just an error in the INSERT/UPDATE statement when the app fires the trigger (?).
Scott PletcherSenior DBACommented:
The trigger code itself would be extremely helpful.

Also, certain types of statements may not fire triggers, such as BULK INSERTs.  Verify that your app isn't using that type of statement.  Not likely but I mention it just to be thorough.
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

bbaleyAuthor Commented:
I am running SQL Profiler trace (with SP:StatementCompleted, SP:StatementStarted selected) and I see the insert or update happen, but the trigger does not show up in the trace.

Primarily I wanted to make sure there was nothing specific to TempDB I should be aware of.

I can execute all code in a test script outside the trigger to verify no errors in the executing code by replacing the INSERTED table reference with a #temp table reference, etc. (in other words I have code that puts a record into a table called #INSERTED and I replace that in the test code etc.)

here is the trigger code:
(along with some debugging stuff in there  I was trying...)
USE [tempdb]
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[trg_Insert_iFixLog]'))
DROP TRIGGER [dbo].[trg_Insert_iFixLog]
USE [tempdb]

CREATE TRIGGER [dbo].[trg_Insert_iFixLog]
   ON  [tempdb].[dbo].[iFix]
   --with execute as owner  

--PRINT 'trigger fired!'

      UPDATE(A_ALMEXT2) or
      UPDATE(A_AUTO) or
      UPDATE(A_CV) or
      UPDATE(A_DESC) or
      UPDATE(A_ENAB) or
      UPDATE(F_CV)  or
      begin try
            --print 'begin try'
            SET NOCOUNT ON;

            declare @date datetime
            SET @date = GETDATE()
            --EXEC iFixLogging.dbo.sp_UPSERT_LogData(
            declare @tagname varchar(60)
            SET @tagname = (SELECT TagName FROM INSERTED)
            --print 'got tag name ' + @tagname
            declare @recs int
            SELECT @recs = (SELECT COUNT(*) FROM  iFixLogging.dbo.iFix_LogData WHERE TagName = @tagname)
            --print 'got rec count' + STR(@recs)
            IF (@recs <= 0)
                  --print 'inserting!'
                  INSERT INTO
                        iFixLogging.dbo.iFix_LogData (
                         from inserted)       
                  UPDATE i --iFix_Logging.dbo.iFix_LogData
                  --      i.TagIndex            = u.TagIndex
                  --   ,i.TagName            = u.TagName
                     i.A_ALMEXT1            = u. A_ALMEXT1
                     ,i.A_ALMEXT2            = u.A_ALMEXT2
                     ,i.A_AUTO            = u.A_AUTO
                     ,i.A_CV                  = u.A_CV
                     ,i.A_DESC            = u.A_DESC
                     ,i.A_ENAB            = u.A_ENAB
                     ,i.A_NAME            = u.A_NAME
                     ,i.F_CV                  = u.F_CV
                     ,i.LastModified  = @date
                        iFixLogging.dbo.iFix_LogData i
                  INNER JOIN
                        INSERTED u
                        --u.TagName = i.tagName and u.TagIndex = i.TagIndex
                        u.TagIndex = i.TagIndex
                  --print 'inserted record'      
      end try
      begin catch
            ERROR_NUMBER() AS ErrorNumber,
            ERROR_SEVERITY() AS ErrorSeverity,
            ERROR_STATE() AS ErrorState,
            ERROR_PROCEDURE() AS ErrorProcedure,
            ERROR_LINE() AS ErrorLine,
            ERROR_MESSAGE() AS ErrorMessage;
            RAISERROR('Error in iFixLogging Trigger' ,16,1) WITH LOG
Scott PletcherSenior DBACommented:
I know you cannot create a trigger on a temp table, but I'm pretty sure that you can add triggers to non-temp tables in the tempdb database.

The trigger should definitely do something for INSERTs.  UPDATEs would only do something if they SET one of the tested columns (IF UPDATE(...)).

Verify that table:

exists and that the user executing the trigger has authority to INSERT and UPDATE that table at least.
bbaleyAuthor Commented:
the answer is;

The application that was writing to the table, was doing so in batch mode (adodb.UpdateBatch) - which does not fire triggers!

Thank you all for your input !
bbaleyAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for bbaley's comment #37799178

for the following reason:

The solution provided solves the problem
Anthony PerkinsCommented:
I have re-opened this question to allow you to do the right thing.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.