WinService LogOn Event insert Sql Server Db

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolaihasan
    New Member
    • Jul 2009
    • 2

    WinService LogOn Event insert Sql Server Db

    Hi,
    i m not much good in windows services. wanna create one so when a user logIn (to his system) it inserts the time with userid in Sql server db. and same at logoff

    How catch event for logon/off?

    Thanx

    Code:
    protected override void OnStart(string[] args)
            {   
                eventLog1.WriteEntry("In OnStart Service");
    
    
                SqlConnection con = new SqlConnection();
    
                con = new SqlConnection(@"Data Source=.\SQLEXPRESS;database=DB;User Id=sa; Password=sa; Integrated Security=SSPI;");
    
                con.Open();
    
                SqlCommand cmd = new SqlCommand("MySp", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@CountryName", "Sudan");
                cmd.ExecuteNonQuery();
    
            }
    Last edited by tlhintoq; Feb 23 '10, 03:46 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    The best method would be using 'sp_who' , "sp_who2" to see which user is connected to which database.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

      Comment

      Working...