Solved

Trigger not working on Sql 2008 server database from my laptop?

Posted on 2012-04-09
9
321 Views
Last Modified: 2012-08-14
Hi,

There are Entered_date and Enetered_by fields on each of tables.
The production database is on the network server. Those two fields are populated fine.
But when I test my application against a test database server on my laptop.
Two fields are not populated.

Two fields are populated by a trigger from this:

ALTER TRIGGER [dbo].[AuditIns_tblxxxx]
   ON [dbo].[tblxxxx]
   AFTER INSERT
AS
BEGIN

      SET NOCOUNT ON;

      update [dbo].[tblxxx]
      set Entered_date = current_timestamp, Entered_By = system_user
      from inserted i
      INNER JOIN [dbo].[tblxxx] t on i.[IdGuid] = t.[IdGuid];


END

So it looks like this line is not working when I run my sql server on my laptop.
set Entered_date = current_timestamp, Entered_By = system_user

Any suggestion as why it is not working?
0
Comment
Question by:dkim18
  • 5
  • 4
9 Comments
 

Author Comment

by:dkim18
ID: 37823261
It looks like the problem is the trigger is not running.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 37823303
The trigger might be disabled on the test database.  Run the following query to verify.  The is_disabled column should be 0 (zero) if the trigger is enabled.
SELECT *
  FROM [YourDatbase].[sys].[triggers]
  WHERE Name = 'AuditIns_tblxxxx'

Open in new window

0
 

Author Comment

by:dkim18
ID: 37823318
It didn't bring back any records.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37823336
Humm... try running the query without the WHERE clause.  BTW, has the trigger been created on your test database?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:dkim18
ID: 37823357
A copy of the database was attached to my local sql server so it has the tiggers.
I can see it from the table's trigger property.
0
 

Author Comment

by:dkim18
ID: 37823373
The production sql server brought back records with trigger names.
SELECT name, is_disabled FROM sys.triggers

But not from my local sql server.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37823381
Does SELECT * FROM [YourDatabase].[sys].[triggers] return any rows?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37823387
I'm not sure why that happened, but it seems the solution is to recreate the triggers on the test database.
0
 

Author Comment

by:dkim18
ID: 37823393
Sorry.
You are right. The tiggers are not there on the local test server.
I am pretty sured I've seen them but not now I don't see them any more.

The my sql server just froze and I had to restart it but I don't see why the trigger would not be there.
All I did was attached the copy of the production database to my local test sql server.
Thanks.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now