0

Hi I have a timer so that when it goes off it will access the database however it doesn't appear to be working. I've never used timers before so not sure if I've written it correctly. The code for the timer is:

 public void timer_method()
        {
            int heartbeat = Convert.ToInt32(textBox1.Text);
            int ms = heartbeat * 1000;

            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(onTimerEvent);
            aTimer.Interval = ms;
            aTimer.Start();
        }

        private void onTimerEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            //throw new NotImplementedException();
            String svcGuid = "e43a8a14-be7f-4367-8420-0fd0f6273bf0";
            Guid gu = new Guid(svcGuid);

            SqlCommand sql = new SqlCommand("sp_idle");
            sql.CommandType = CommandType.StoredProcedure;
            sql.Connection = conn;
            sql.Parameters.AddWithValue("@id", gu);
            sql.Parameters.Add(new SqlParameter()
            {
                ParameterName = "RETURN_VALUE",
                Direction = ParameterDirection.ReturnValue
            });

            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
                sql.ExecuteNonQuery();
            }


            MessageBox.Show("test");
        }

At the minute when I run the code the message box appears every x seconds however the stored procedure doesn't run. Thanks in advance.

3
Contributors
4
Replies
17
Views
1 Year
Discussion Span
Last Post by coder91
0

Thank you, this seems to have worked, have an error message saying An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code Additional information: Operand type clash: uniqueidentifier is incompatible with int. Assuming this is the type being passed to the stored procedure?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.