0

I have a aspnetcore webservice which does several requests after one another. I get an exception at different times. the Error message is:

MySql.Data.MySqlClient.MySqlException: error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

at MySql.Data.MySqlClient.MySqlPool.GetConnection()

at MySql.Data.MySqlClient.MySqlConnection.Open()

at bdtFood.Controllers.FoodController.Get(Int32 id, Int32 idMeeting)

at lambda_method(Closure , Object , Object[] )

at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__28.MoveNext()

How can i pervent this exception. There shouldn't be more than one request at the same time.

EDIT: code for a request.

while (cn.State == System.Data.ConnectionState.Open)
        {

        }
        cn.Close();
        cn.Open();
        Modells.Room room = new Modells.Room(-2, "dummy");
        MySqlCommand myCommand = new MySqlCommand("SELECT * FROM room WHERE idRoom = @idRoom", cn);
        myCommand.Parameters.Add("@idRoom", MySqlDbType.Int32, 11).Value = idRoom;
        using (reader = myCommand.ExecuteReader())
        {
            while (reader.Read())
            {
                room = new Modells.Room(reader.GetInt32(0), reader[1].ToString());
            }
        }
Cœur
  • 37,241
  • 25
  • 195
  • 267
tatatoto
  • 138
  • 1
  • 12
  • Are you disposing your connections and commands? – mjwills Jul 10 '17 at 13:17
  • I for every request I use a new connection and a new command. Could this be the problem? I thought this would not be the problem because I use them one at a time. – tatatoto Jul 10 '17 at 13:18
  • It is impossible to give you any other more specific advice without seeing some of your code. – mjwills Jul 10 '17 at 13:20
  • I changed my code to using the same connection within a controller. and the same error still occurs – tatatoto Jul 10 '17 at 13:32

1 Answers1

0

You need to use using around all Commands and Controllers.

See https://stackoverflow.com/a/1808056/34092 for more details.

mjwills
  • 23,389
  • 6
  • 40
  • 63