Question

I'm working with mysql database using entity framework(DevArt's data providers). I've noticed that sometimes in logs i get such exception:

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.
---> Devart.Data.MySql.MySqlException: Lost connection to MySQL server during query
---> System.TimeoutException: Server did not respond within the specified timeout interval.
---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

And that exception is happening several times simultaneously(? dropping several connections at once..) and after it happens - everything works fine for some time. I've tried

I know that this error is probably too general, but need an advice on what to do to avoid that?.. Tried increasing connections in pool and Validate Connection=true; - no luck.

Was it helpful?

Solution

The possible reasons of the "Lost connection to MySQL server during query" error:

  1. connection was closed by MySQL server:

    • look for any errors in the logs of MySQL server

    • check the value of wait_timeout variable at your MySQL server

  2. network problems

  3. the issue is specific to dotConnect for MySQL: set "Validate Connection=true;" option in the connection string to validate connection each time on retrieving it from the pool (less performance, should be used in the environment with unstable connections). If "Validate Connection=false;" (default) - connection is validated only in the pool every ~30 seconds (no check no retrieving it from the pool)

If you are explicitly providing plain ADO.NET connection to your DbContext (or ObjectContext) object, take into account the following points:

  1. the MySqlConnection object is not thread safe. You should avoid using the same MySqlConnection in several threads at the same time

  2. you can implement a failover logic in your application:

OTHER TIPS

Seems that update to the september 2013 version of mysql provider(august 2013 was installed) and disabling connection pooling helped in this situation. Will wait 1 day, then enable pooling. If this works too - than this was "version's" fault, in other case - disabling connection pool helps.

This also happened to me but nothing worked for me I guess I don't fall in the above use case. Devart has got Default Command Timeout which seems to be stopping the execution after the default timeout which is 30 seconds.

Devart suggested to set this value in the connection string (;Default Command Timeout=6000;) but connection string 'Default command timeout' value doesn't seem to get honoured so finally I updated the command timeout value in the code like below which solved my problem.

            using (var model = new MyEntities())
            {
                System.Data.Entity.DbContext dbContext = model as System.Data.Entity.DbContext;
                dbContext.Database.CommandTimeout = 6000;
                model.CallProcedure1(idProcess);
                model.CallProcedure2(idProcess);
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top