简体   繁体   English

Devart.Data.MySql.MySqlDependency不适用于多个连接

[英]Devart.Data.MySql.MySqlDependency does not work on multiple connections

i have a problem concerning the Devart.Data.MySql.MySqlDependency class. 我对Devart.Data.MySql.MySqlDependency类有问题。 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] 净数据包乱序:已接收[1],预期[7]

I cannot handle this error using MySqlException. 我无法使用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. 这是我用来运行这两个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 我真的很感谢在这件事上的帮助

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 . 这似乎与文档显示的用法更加一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM