Example #1
0
        public void RegisterDependency()
        {
            using (SqlConnection connection = new SqlConnection(ConnectHelper.ConnectConnectionString()))
            {
                try
                {
                    SqlCommand command = new SqlCommand("SELECT [Last Login], [Application Running], [User Name], [Computer Name], [Version] FROM [dbo].[Checkin] ", connection);

                    //Monitor the Service Broker, and get notified if there is change in the query result
                    SqlDependency dependency = new SqlDependency(command, "Service=SPMConnectClientService;local database=SPM_Database", int.MaxValue);

                    //Fire event when message is arrived
                    dependency.OnChange += this.Dependency_OnChange;

                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    SqlDataReader reader = command.ExecuteReader();
                    //while (reader.Read())
                    //{
                    //    Leave leave = new Leave();
                    //    leave.ID = reader["Computer Name"].ToString();
                    //    leave.ApplicantName = reader["Application Running"].ToString();
                    //    leave.Status = reader["User Name"].ToString();

                    //    Console.WriteLine(string.Format("{0}\t{1}\t{2}", leave.ID, leave.ApplicantName, leave.Status));
                    //}
                    connection.Close();
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(string.Format("Error: {0}", ex.Message));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format("Error: {0}", ex.Message));
                }
            }
        }
Example #2
0
 public void Dispose()
 {
     SqlDependency.Stop(ConnectHelper.ConnectConnectionString(), "SPMConnectClientsQueue");
 }
Example #3
0
 public SQLNotifier()
 {
     SqlDependency.Start(
         ConnectHelper.ConnectConnectionString(),
         "SPMConnectClientsQueue");
 }