I need to keep track of the last login time for each user in our SQL Server 2005 database.

I created a trigger like this:

CREATE TRIGGER LogonTimeStamp
ON ALL SERVER FOR LOGON
AS
BEGIN
  IF EXISTS (SELECT * FROM miscdb..user_last_login WHERE user_id = SYSTEM_USER)
    UPDATE miscdb..user_last_login SET last_login = GETDATE() WHERE user_id = SYSTEM_USER
  ELSE
    INSERT INTO miscdb..user_last_login (user_id,last_login) VALUES (SYSTEM_USER,GETDATE())
END;
go

This trigger works for users that are system admins but it won't allow regular users to login. I have granted public select,insert and update to the table but that doesn't seem to be the issue. Is there a way to set permissions on the trigger? Is there something else I am missing?

Thanks

link|improve this question
What is the error that users receive when logging in? – mrdenny Jan 11 '11 at 21:29
Logon failed for login 'xxxx' due to trigger execution. Changed database context to 'xxxx', Changed language setting to us_english. (Microsoft SQL Server, Errror: 17892). – Jay Jan 12 '11 at 2:42
System administrator accounts can get in fine, but anyone who isn't a system administrator gets this error. – Jay Jan 12 '11 at 2:43
The problem is that every user with a login to the server isn't a user in the miscdb database. If they aren't a user in miscdb, they can't login. We don't want to have to remember to add users to this database when we add them to the database they need. Is there a way to grant rights to all logins of the server? – Jay Jan 12 '11 at 16:52
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.