Hi,
We are using MySqlDependency for monitoring changes on a table. The issue is when some error is triggered for connection slow down or drop. I couldn't find anyway on manual to threat errors. How are we supposed to do so ?
This keep crashing app.
MySqlDependency Error
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: MySqlDependency Error
You can use the LocalFailover property of MySqlConnection object. It allows performing the failover operation after connection breaks. For more information, please refer to http://www.devart.com/dotconnect/mysql/ ... lover.html
When the LocalFailover property is set to 'True', then the LostConnection event can be used. In the event handler you can specify, that the connection should be re-opened, not an exception raised.
http://www.devart.com/dotconnect/mysql/ ... st_EV.html
http://www.devart.com/dotconnect/mysql/ ... yMode.html
However, the MySqlDependency object doesn't provide access to MySqlConnection it uses. And there is no ConnectionString parameter that would establish the LocalFailover property to 'True' for this connection.
We will investigate the possibility to implement the LocalFailover parameter for the connection string and notify you about the results as soon as possible.
When the LocalFailover property is set to 'True', then the LostConnection event can be used. In the event handler you can specify, that the connection should be re-opened, not an exception raised.
http://www.devart.com/dotconnect/mysql/ ... st_EV.html
http://www.devart.com/dotconnect/mysql/ ... yMode.html
However, the MySqlDependency object doesn't provide access to MySqlConnection it uses. And there is no ConnectionString parameter that would establish the LocalFailover property to 'True' for this connection.
We will investigate the possibility to implement the LocalFailover parameter for the connection string and notify you about the results as soon as possible.
Re: MySqlDependency Error
Hi,
I see. So we have to wait for this implementation on MysqlDependency as it doesn't allow acessing the connection, right ?
No other ways to temporarily avoid the crash ?
Best regards,
Daniel Bichuete
I see. So we have to wait for this implementation on MysqlDependency as it doesn't allow acessing the connection, right ?
No other ways to temporarily avoid the crash ?
Best regards,
Daniel Bichuete
Re: MySqlDependency Error
This is correct.bichuete wrote:So we have to wait for this implementation on MysqlDependency as it doesn't allow acessing the connection, right ?
Currently there is no way.bichuete wrote:No other ways to temporarily avoid the crash ?
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: MySqlDependency Error
We have added the overload for the MySqlDependency.Start method with the MySqlConnection parameter. We will notify you when the corresponding build of dotConnect for Oracle is available for download.
Below is the description of how the new overloaded method can be used for restoring a connection to the MySQL database when using MySqlDependency.
Now you can pass the MySqlConnection object with the customized LocalFailover property as a MySqlDependency.Start method parameter.
Below is a small example demonstrating how the MySqlDependency.Start overloaded method can be used:
After running the application do the following:
1. Make some changes to the dept table – this will result in the OnChange event handling;
2. Simulate connection loss, e.g. you can disable network connection in your system network environment, this will result in the ConnectionLost event handling;
3. Restore network connection;
4. Perform step 1.
Below is the description of how the new overloaded method can be used for restoring a connection to the MySQL database when using MySqlDependency.
Now you can pass the MySqlConnection object with the customized LocalFailover property as a MySqlDependency.Start method parameter.
Below is a small example demonstrating how the MySqlDependency.Start overloaded method can be used:
Code: Select all
static void Main(string[] args)
{
string str = "User Id=your user;Password=your password;Host=your host;Port=3306;Database=your database;";
MySqlConnection connection = new MySqlConnection(str);
connection.LocalFailover = true;
connection.ConnectionLost += new ConnectionLostEventHandler(connection_ConnectionLost);
connection.Open();
MySqlCommand cmd = new MySqlCommand("select * from dept", connection);
MySqlDependency depend = new MySqlDependency(cmd, 1000);
depend.OnChange += new Devart.Data.MySql.OnChangeEventHandler(depend_OnChange);
MySqlDependency.Start(connection);
Thread.Sleep(500 * 1000); // sleep main thread
MySqlDependency.Stop(str);
Console.WriteLine("Finish");
Console.ReadKey();
}
static void connection_ConnectionLost(object sender, ConnectionLostEventArgs e)
{
Console.WriteLine("AttemptNumber: {0}", e.AttemptNumber);
if (e.AttemptNumber < 15)
{
// Thread.Sleep(10000) if need to reduce interval beetween Reexecute
e.RetryMode = RetryMode.Reexecute; // try to reconnect and reexecute check command
}
else
e.RetryMode = RetryMode.Raise; // skip Reexecute and throw exception
}
static void depend_OnChange(object sender, MySqlTableChangeEventArgs e)
{
Console.WriteLine("{0} was changed.", e.TableName);
}
1. Make some changes to the dept table – this will result in the OnChange event handling;
2. Simulate connection loss, e.g. you can disable network connection in your system network environment, this will result in the ConnectionLost event handling;
3. Restore network connection;
4. Perform step 1.
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: MySqlDependency Error
The new build of dotConnect for MySQL 7.2.132 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/mysql/download.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?t=25386
It can be downloaded from http://www.devart.com/dotconnect/mysql/download.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?t=25386