MySqlDependency Error

MySqlDependency Error

Postby bichuete » Thu 01 Nov 2012 04:50

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.
bichuete
 
Posts: 3
Joined: Wed 21 Dec 2011 18:16
Location: Brasil

Re: MySqlDependency Error

Postby Pinturiccio » Thu 01 Nov 2012 16:03

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/docs/?Devart.Data.MySql~Devart.Data.MySql.MySqlConnection~LocalFailover.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/docs/?Devart.Data.MySql~Devart.Data.MySql.MySqlConnection~ConnectionLost_EV.html
http://www.devart.com/dotconnect/mysql/docs/?Devart.Data~Devart.Common.RetryMode.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.
Pinturiccio
Devart Team
 
Posts: 1893
Joined: Wed 02 Nov 2011 09:44

Re: MySqlDependency Error

Postby bichuete » Sat 03 Nov 2012 04:58

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
bichuete
 
Posts: 3
Joined: Wed 21 Dec 2011 18:16
Location: Brasil

Re: MySqlDependency Error

Postby Shalex » Wed 07 Nov 2012 10:29

bichuete wrote:So we have to wait for this implementation on MysqlDependency as it doesn't allow acessing the connection, right ?
This is correct.

bichuete wrote:No other ways to temporarily avoid the crash ?
Currently there is no way.
Shalex
Devart Team
 
Posts: 7460
Joined: Thu 14 Aug 2008 12:44

Re: MySqlDependency Error

Postby Pinturiccio » Wed 28 Nov 2012 15:57

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:
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);
}

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.
Pinturiccio
Devart Team
 
Posts: 1893
Joined: Wed 02 Nov 2011 09:44

Re: MySqlDependency Error

Postby Pinturiccio » Thu 29 Nov 2012 14:57

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
Pinturiccio
Devart Team
 
Posts: 1893
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for MySQL