MySql.Data.MySqlClient.MySqlException Timeout Expired c#

0

i'm getting error

MySql.Data.MySqlClient.MySqlException Timeout Expired

in this in MySqlReader

My code

public MySqlReader(MySqlCommand command)
        {
            if (command.Type == MySqlCommandType.SELECT)
            {
                _dataset = new DataSet();
                _row = 0;
                using (MySql.Data.MySqlClient.MySqlConnection conn = DataHolder.MySqlConnection)
                {
                    conn.Open();
                    using (var DataAdapter = new MySqlDataAdapter(command.Command, conn))
                        DataAdapter.Fill(_dataset, Table);
                    ((IDisposable)command).Dispose();  // in this line
                }
            }
        }

What can i do to fix this?

Full error:

[04:46:58] MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation or the server i s not responding. ---> System.TimeoutException: A connection attempt failed beca use the connected party did not properly respond after a period of time, or esta blished connection failed because connected host has failed to respond ---> Syst em.IO.IOException: Unable to read data from the transport connection: A connecti on attempt failed because the connected party did not properly respond after a p eriod of time, or established connection failed because connected host has faile d to respond. ---> System.Net.Sockets.SocketException: A connection attempt fail ed 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.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s ize) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s ize) at MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) --- End of inner exception stack trace --- at MyNetworkStream.HandleOrRethrowException(Exception e) at 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() at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& i nsertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior ) at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exceptio n ex) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior ) at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior be havior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandB ehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand co mmand, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) at DeadPool.Database.MySqlReader..ctor(MySqlCommand command) in C:\Users\Admi nistrator\Desktop\NewSource\Source\Database\MySql\MySqlReader.cs:line 26 at DeadPool.Database.SkillTable.LoadSpells(GameState client) in C:\Users\Admi nistrator\Desktop\NewSource\Source\Database\SkillTable.cs:line 161
at DeadPool.Database.SkillTable.LoadSpells(GameState client, MySqlConnection conn) in C:\Users\Administrator\Desktop\NewSource\Source\Database\SkillTable.cs: line 184 at DeadPool.Client.GameState.LoadData(Boolean loadFake) in C:\Users\Administr ator\Desktop\NewSource\Source\Client\GameState.cs:line 6290 at DeadPool.Network.PacketHandler.DoLogin(GameState client) in C:\Users\Admin istrator\Desktop\NewSource\Source\Network\PacketHandler.cs:line 27490 at DeadPool.Network.PacketHandler.AppendConnect(Connect appendConnect, GameSt ate client) in C:\Users\Administrator\Desktop\NewSource\Source\Network\PacketHan dler.cs:line 27434 at DeadPool.Network.PacketHandler.HandlePacket(Byte[] packet, GameState clien t) in C:\Users\Administrator\Desktop\NewSource\Source\Network\PacketHandler.cs:l ine 2494 at DeadPool.Program.processData(Byte[] buffer, Int32 length, GameState Client ) in C:\Users\Administrator\Desktop\NewSource\Source\Program.cs:line 1353
at DeadPool.Program.GameServer_OnClientReceive(Byte[] buffer, Int32 length, C lientWrapper obj) in C:\Users\Administrator\Desktop\NewSource\Source\Program.cs: line 1336 at DeadPool.Network.Sockets.ClientWrapper.doReceive(Int32 available) in C:\Us ers\Administrator\Desktop\NewSource\Source\Network\Sockets\ClientWrapper.cs:line 121

c#
linq
stored-procedures
timeoutexception
asked on Stack Overflow Aug 24, 2016 by Kareem Maystro • edited Aug 24, 2016 by Kareem Maystro

1 Answer

0

Increase the time out by setting the command object property: CommandTimeout. I believe the default value is 30 (in seconds).

So, your updated method:

public MySqlReader(MySqlCommand command)
{
    //HERE!!!!
    command.CommandTimeout = 60;

    if (command.Type == MySqlCommandType.SELECT)
    {
         _dataset = new DataSet();
         _row = 0;
         using (MySql.Data.MySqlClient.MySqlConnection conn = 
             DataHolder.MySqlConnection)
         {
             conn.Open();
             using (var DataAdapter = new MySqlDataAdapter(command.Command, conn))
                  DataAdapter.Fill(_dataset, Table);
                 ((IDisposable)command).Dispose();  // in this line
        }
    }
}
answered on Stack Overflow Nov 11, 2019 by Jahmic

User contributions licensed under CC BY-SA 3.0