MySql.Data.MySqlClient.MySqlException :Fatal error encountered during command execution.
Posted by: vrushali katkade
Date: January 06, 2020 12:14AM

Dear Support,



I have been having the following error message that some time 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



my code:

static System.Threading.Timer timer;
static void Main(string[] args)
{


System.Threading.TimerCallback callback = new System.Threading.TimerCallback(insert);
timer = new System.Threading.Timer(callback, null, 1000, 1000);

System.Threading.Thread.Sleep(Timeout.Infinite);



}

public static void insert(object obj)
{
try
{

MySqlConnection con1 = new MySqlConnection();
MySqlDataAdapter ODA;


con1.ConnectionString = "server=localhost;uid=root;pwd=Stpl@1234;database=s1;port=3306;Allow User Variables=True;Connect Timeout=30";

string query1="", insertquery = "";
for (int i=0;i<10000;i++)
{
query1 += "select " + i + " as DTvalue Union " + Environment.NewLine;

}

// string query1 += "select '" + obj1 + "' as DTvalue ," + readingdata[counter1].Quality + " as DTquality ,'" + datetm + "' as DTtimestamp ," + readingdata[counter1].HandleClient + " as DTparamID Union " + Environment.NewLine;



if (query1 != "")
{
query1 = query1.Remove(query1.LastIndexOf("Union"));
insertquery += " insert into t1 " + Environment.NewLine;
insertquery += "(id)" + Environment.NewLine;
insertquery += " " + query1 + " ";
if (con1.State == ConnectionState.Closed)
con1.Open();
using (MySqlCommand cmd1 = new MySqlCommand(insertquery, con1))
{
cmd1.ExecuteNonQuery();
}
if ((con1.State == ConnectionState.Connecting) || (con1.State == ConnectionState.Open))
con1.Close();
}
}
catch(Exception ex)
{

}
}



in insert function exception is coming .


Thanks

Options: ReplyQuote


Subject
Written By
Posted
MySql.Data.MySqlClient.MySqlException :Fatal error encountered during command execution.
January 06, 2020 12:14AM


Sorry, you can't reply to this topic. It has been closed.

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.