0

i have a problem concerning the Devart.Data.MySql.MySqlDependency class. I want to have two dependencies checking the database for changes, but some how i get the error:

Net packets out of order: received[1], expected[7]

I cannot handle this error using MySqlException. When i run one dependency it works fine, but when i use two it fails, and raises the exception.

This is the code i use to run these two SqlDependencies.

public void register(string id) {

        try
        {
            dept = new MySqlDependency();
            dept.AddCommandDependency(objcom);
            dept.CheckTimeout = 100;
            dept.OnChange += Dept_OnChange2;
            objcom.Connection.Name = id;
            string connection = objcom.Connection.ConnectionString;
            MySqlDependency.Start(connection);

        }  catch(MySqlException err) {//The exception is not being handled here}
    }

I create a new instance of the class this is in, and then i call the method. I do this two times, it looks like this:

MySqlConnection objcon = new MySqlConnection(databasekoplingsadresse_devart());
        MySqlConnection objcon_ = new MySqlConnection(databasekoplingsadresse_devart());

        SqlDependenCyHandler depthandler = new SqlDependenCyHandler(objcon, "select * from messages");
        depthandler.register("obj1");

        SqlDependenCyHandler depthandler2 = new SqlDependenCyHandler(objcon_, "select * from tasks");
        depthandler2.register("obj2");

I would really appreciate help on this matter

blueio22
  • 48
  • 7

1 Answers1

1

Instead of instantiating two different dependencies, can you just add the different dependencies to the same object? Something like (untested code):

MySqlConnection objcon = new MySqlConnection(databasekoplingsadresse_devart());
MySqlCommand cmdMsg = new MySqlCommand("select * from messages", objcon); 
MySqlCommand cmdTasks = new MySqlCommand("select * from tasks", objcon); 

MySqlDependency dependency = new MySqlDependency(cmdMsg, 100); 
dependency.AddCommandDependency(cmdTasks); 
dependency.OnChange += Dept_OnChange2
MySqlDependency.Start(objcon.Connection.ConnectionString); 

This seems more inline with the usage showed by the documentation.

scotru
  • 2,563
  • 20
  • 37