Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

Last post 08-29-2008, 6:22 AM by MVV. 8 replies.
Sort Posts: Previous Next
  •  08-26-2008, 6:31 AM Post number 69265

    Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    I am trying to create a trigger that will fire once for each user as they connect and disconnect.  Any suggestions?
  •  08-26-2008, 10:31 AM Post number 69273 in reply to post number 69265

    • MVV is not online. Last active: 12-12-2008, 4:35 AM MVV
    • Top 25 Contributor
    • Joined on 04-29-2008
    • Alcoy, Spain
    • Level 2: Deep Blue

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    Since you are dealing with the sqlserver and not with data , the only way i see you can do this is using @@CONNECTIONS if you only care to know the load , or go for it with sp_who

    I'm assuming here you are using SQLServer 2000 and have no control over the querys launched against the sqlserver.

    You can program a job that gets the result of sp_who into a table , compare the users with the last run of the job and if there is a difference , fire a sp where you do whatever you want to do (log in/out times)

    This has some drawbacks , of course. Depending on the programming of the job , you can load too much the server if you program it to fire too continuosly , or you can miss enters and exits if they are quicker than your job. But is easy and doable.

    HTH

    Hey , sysadm , leave the users alone
    They are nothing more
    than another brick in the firewall
  •  08-26-2008, 10:34 AM Post number 69274 in reply to post number 69273

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    I am actually using SQLServer 2005 does that make a difference? Sorry, new to MS SQL. 

    EW

     

  •  08-26-2008, 10:42 AM Post number 69275 in reply to post number 69274

    • MVV is not online. Last active: 12-12-2008, 4:35 AM MVV
    • Top 25 Contributor
    • Joined on 04-29-2008
    • Alcoy, Spain
    • Level 2: Deep Blue

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    Don't know if SQL2005 has some more facilities , just that SQL2000 is the one i'm more confortable and you didn't specify.

    Anyhow , i googled a little a found something you could use if you go for the job option

    http://www.sqlserver.org.au/resources/ViewResource.aspx?resourceId=8

    more or less what i told you , but well written , documented and with the complete code :)


    Hey , sysadm , leave the users alone
    They are nothing more
    than another brick in the firewall
  •  08-26-2008, 1:09 PM Post number 69280 in reply to post number 69275

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    I am sorry for the basic nature of this question, but after reviewing the example you provided I decided to try a simple stored procedure that I can call from my program.  I have sysadmin rights to this test db but when I save the stored procedure it does not appear in Management studieo anywhere.

    Where am I messing up?

    EW

     

  •  08-26-2008, 1:21 PM Post number 69281 in reply to post number 69280

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    Never mind I figured it out.  I needed to execute the stored procedure to create it.

    Thanks.

    EW

  •  08-29-2008, 4:34 AM Post number 69316 in reply to post number 69265

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    It’s much easier to catch login event in sql 2005

    Review following document

    http://msdn.microsoft.com/en-us/library/bb326598(SQL.90).aspx

     

  •  08-29-2008, 6:05 AM Post number 69317 in reply to post number 69316

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    That is what I needed to know thanks.
  •  08-29-2008, 6:22 AM Post number 69318 in reply to post number 69316

    • MVV is not online. Last active: 12-12-2008, 4:35 AM MVV
    • Top 25 Contributor
    • Joined on 04-29-2008
    • Alcoy, Spain
    • Level 2: Deep Blue

    Re: Trigger Question - Is there a way to create a trigger that fires when a user connects and another trigger when they disconnect?

    nice link , thanks for sharing , i'll surely use it sometime soon :)

    Hey , sysadm , leave the users alone
    They are nothing more
    than another brick in the firewall
View as RSS news feed in XML