Hi all,
I have a table called Session which holds the session information of each user who logins to our internal non-web based application.
As soon as the user logout the Session table removes the record for that user. So the user records is only active in to the session table as long as the user is active.
The Session table has the following fields with thier data type:
UserID(uniqueidentifier),SessionID(uniqueidentifier),Spid(int),StartTime(DateTime),Duration(DateTime),ActivitySID(uniqueidentifier),Location(varchar),LanguageID(int),UserDomain(nvarchar),UserID(nvarchar),FirstName(nvarchar),LastName(nvarchar),IsAdminuser (bit)
The SessionID is the PrimaryKEY.
Now, I need to keep track of users who login anytime in to the application.
To start with, I created a insert trigger on Session table, which insert a new record into a table UserTrack , whenever there's an insert on Session table. It inserts all fields into the UserTrack table for that new user.
The following trigger for this purpose works fine:
--Insert trigger
create Trigger InsertUser
on Session
For insert
as
if update(SessionSID)
insert into UserTrack
select * from inserted
--End of insert trigger
Now as mentioned before the Session table keep records only as long as the user is active & as soon as the user logout the record is deleted .
Now, finally I want to create a delete trigger on the same Session table.
That is, when a user logsout (which mean, when a record is deleted from Session table) update the UserTrack table, set the Duration (datetime type) field to current time, where ofcourse the Session.SessionSID=deleted.SessionSid
For this purpose, I created this Trigger:
--Delete trigger
create Trigger InsertLogoutTimeForUser
on Session
For Delete
as
if update(SessionSID)
update UserTrack
set UserTrack.Duration=getdate()
from UserTrack join Deleted
on (UserTrack.SessionSID=deleted.SessionSID)
--End of Delete trigger
When, I am quering the UserTrack table the Duration is not updating.
Any idea?.
Thanks a million in advance...
Looking for a quick response.
Thanks,
I have a table called Session which holds the session information of each user who logins to our internal non-web based application.
As soon as the user logout the Session table removes the record for that user. So the user records is only active in to the session table as long as the user is active.
The Session table has the following fields with thier data type:
UserID(uniqueidentifier),SessionID(uniqueidentifier),Spid(int),StartTime(DateTime),Duration(DateTime),ActivitySID(uniqueidentifier),Location(varchar),LanguageID(int),UserDomain(nvarchar),UserID(nvarchar),FirstName(nvarchar),LastName(nvarchar),IsAdminuser (bit)
The SessionID is the PrimaryKEY.
Now, I need to keep track of users who login anytime in to the application.
To start with, I created a insert trigger on Session table, which insert a new record into a table UserTrack , whenever there's an insert on Session table. It inserts all fields into the UserTrack table for that new user.
The following trigger for this purpose works fine:
--Insert trigger
create Trigger InsertUser
on Session
For insert
as
if update(SessionSID)
insert into UserTrack
select * from inserted
--End of insert trigger
Now as mentioned before the Session table keep records only as long as the user is active & as soon as the user logout the record is deleted .
Now, finally I want to create a delete trigger on the same Session table.
That is, when a user logsout (which mean, when a record is deleted from Session table) update the UserTrack table, set the Duration (datetime type) field to current time, where ofcourse the Session.SessionSID=deleted.SessionSid
For this purpose, I created this Trigger:
--Delete trigger
create Trigger InsertLogoutTimeForUser
on Session
For Delete
as
if update(SessionSID)
update UserTrack
set UserTrack.Duration=getdate()
from UserTrack join Deleted
on (UserTrack.SessionSID=deleted.SessionSID)
--End of Delete trigger
When, I am quering the UserTrack table the Duration is not updating.
Any idea?.
Thanks a million in advance...
Looking for a quick response.
Thanks,