1
votes

I've got a MySQL 5.5 DB server, using Entity Framework 4.3, MySQL Connector 6.5.4.

The problem that I'm seeing is that over a slow connection (~192kbs) seems to be fairly consistent.

The scenario is that I first call a method that looks like this:

using (var db = new IceCreamEntities(ConnectionString, null, null, null, "infinite timeout"))
{
   db.desserts.Add(myDessert);
   db.SaveChanges()

   db.dessertData.Add(new dessertBlob() { DessertId = myDessert.Id, Data = someData });
}

and then I call closely after that (say, within 30 seconds or so) a method to get that back. It looks like:

using (var db = new IceCreamEntities(ConnectionString, null, null, null, "infinite timeout"))
{
   var myDessertData = db.dessertData.Where(m => m.DessertId == myId).FirstOrDefault();
   return myDessertData;
}

Now, the IceCreamEntities constructor call there that I'm using does the following:

public IceCreamEntities(string connectionString, string unused2, string unused3, string unused4, string forLongRunningStuff)
: base(connectionString)
{
   var objectContext = (this as IObjectContextAdapter).ObjectContext;
   objectContext.CommandTimeout = 0;
}

(there are a couple other constructors that are used with different timeouts, but that is probably not germane to the discussion)

The blob I'm putting into that dessertData table is about 3 megabytes in size.

When I'm not on a slow connection, I don't see this problem.

The exception I get is:

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.

---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution.

---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered attempting to read the resultset.

---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

--- End of inner exception stack trace ---

at MySql.Data.Common.MyNetworkStream.HandleOrRethrowException(Exception e)

at MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)

at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)

at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)

at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)

at MySql.Data.MySqlClient.MySqlStream.LoadPacket()

--- End of inner exception stack trace ---

at MySql.Data.MySqlClient.MySqlStream.LoadPacket()

at MySql.Data.MySqlClient.MySqlStream.ReadPacket()

at MySql.Data.MySqlClient.NativeDriver.FetchDataRow(Int32 statementId, Int32 columns)

at MySql.Data.MySqlClient.Driver.FetchDataRow(Int32 statementId, Int32 columns)

at MySql.Data.MySqlClient.ResultSet.GetNextRow()

at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)

at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)

at MySql.Data.MySqlClient.MySqlDataReader.NextResult()

--- End of inner exception stack trace ---

at MySql.Data.MySqlClient.MySqlDataReader.NextResult()

at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)

--- End of inner exception stack trace ---

at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)

at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

--- End of inner exception stack trace ---

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)

at System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption)

at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()

at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)

at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)

at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)

at IceCream.Repository.GetDessertData(Int64 dessertId) in ....

One other data point - I can call the method that does the add twice in a row with the same sized blob and I don't get this error (or the equivalent). It only happens when I do an Add and then follow it up with the Retrieve.

Any ideas how to address this? I had thought that settting the command timeout value to 0 would solve my problems but it doesn't.

Edit

One other point is that I did the math and 3 megabytes at 192mbs should take somewhere in the neighborhood of 128 seconds to transfer.

1

1 Answers

3
votes

So, after much searching and reading, I adjusted the following values in the my.ini file:

net_read_timeout

net_write_timeout

By setting those to the value 99999 and restarting my db server, I'm able to now retrieve that 3M file over the slow connection without further incident.