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());
}
}