MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution.
Posted by: Mitchell Kelly
Date: March 27, 2019 09:47PM

I have been having the following error message that randomly appears. Most of the time it works, but it appears that some times it give me this fatal error. It appears to be random, it will work fine for some queries then that same query fails the next time it runs.
I have done some investigating and have tried to increase the connection timeouts and command timeouts, Yet on some machines this happens randomly.

Any suggestions on how to fix these errors.


The following Excpetion was caught:

Fatal error encountered during command execution. MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> 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 at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.LoadPacket() at MySql.Data.MySqlClient.MySqlStream.LoadPacket() at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at Launcher.LodgeDocument.uploadDocument(Int32 selectedRow) in C:\source\repos\Launcher\Launcher\LodgeDocument.cs:line 209 at Launcher.LodgeDocument.dgDocumentView_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) in C:\source\repos\Launcher\Launcher\LodgeDocument.cs:line 147

Related Code for above error:

public void UploadNewFile(int RecID, string FileName, string Username, DateTime timenow)
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = "UPDATE t_doclodgement " +
"SET LodgedBy = @newlodgedBy, " +
"LodgeDateTime = @newlodgeDateTime, " +
"DocFileName = @newDocFileName " +
"WHERE RecID = @RecID ";

cmd.Parameters.AddWithValue("@RecID", RecID);
cmd.Parameters.AddWithValue("@newlodgedBy", Username);
cmd.Parameters.AddWithValue("@newlodgeDateTime", timenow);
cmd.Parameters.AddWithValue("@newDocFileName", FileName);

try
{
ExectueCMD(cmd);
}
catch (MySqlException e)
{
throw (e);

}
}
}




protected bool ExectueCMD(MySqlCommand cmd)
{
int attempt = 0;
bool complete = false;
while (!complete)
{
try
{
using (MySqlConnection connection = OpenConnection(conn_string))
{
cmd.Connection = connection;
cmd.CommandTimeout = 60;
cmd.ExecuteNonQuery();

}
Console.WriteLine("Connection Closed\n");
complete = true;
}
catch (MySqlException e)
{
if (attempt >= 3)
throw e;
else
attempt++;
}
}
return complete;
}

Options: ReplyQuote


Subject
Written By
Posted
MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution.
March 27, 2019 09:47PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.