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.

Try

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

sql.ExecuteNonQuery();

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?

Assuming this is the type being passed to the stored procedure?

Correct.

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.