0

Angular + dotnet core application that hosted on the Linux server(centos) is throwing time out error when try to connect MS SQL Server that installed in azure Virtual machine.

error:

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.

But when I try to run the application in Visual studio editor(localhost and OS in windows) it is working. earlier it was throwing network related issue after whitelisting the IP now I am getting the the above mentioned TIMEOUT error .

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    ///code
 }

also I tried to give min and max pool size and "Integrated Security=false",true sspi etc in connection string.

Thom A
  • 88,727
  • 11
  • 45
  • 75
Aja
  • 23
  • 6
  • Does it happen immediately, or only after running for a period of time? Have you done a review of `new SqlConnection(connectionString)` usages in the code to ensure that they're all in `using` blocks? – AlwaysLearning Aug 29 '22 at 11:49
  • @AlwaysLearning Thanks for the reply ,it happens after running for a period of time. yes I checked all the codes are inside 'using' blocks only. – Aja Aug 31 '22 at 17:28
  • please check this similar [thread](https://stackoverflow.com/questions/23731876/timeout-expired-the-timeout-period-elapsed-prior-to-obtaining-a-connection-from) – Imran Sep 08 '22 at 04:21

1 Answers1

0

If you recall properly, the default value for the Max Pool Size is 100. your code waited for a database connection, but the timeout (which you set) is expired. It depends on how long it takes for your queries to finish for a website. Try to set a higher value in your connection strings: Max Pool Size=200

There was a network time out or the number of connections in the pool (which you set) was too low for the number of connections you were attempting may cause a timeout error

To fix this issue please check this below code:

using (SqlConnection connection = new SqlConnection(connectionString))
{
     connection.Open();
     someCall(connection);
}

Alternatively

var connection = new SqlConnection(ConnectionString);

try
{
     connection.Open();
     someCall (connection);
}
finally
{
     connection.Close();                
}

Please check this similar SO thread credits by splattne

Imran
  • 3,875
  • 2
  • 3
  • 12
  • Thanks for the reply, I tried the above mentioned changes . Also there is no other application or connection is there for the SQL DB(inside VM) i mean it is one on one. – Aja Aug 31 '22 at 17:33
  • please check this similar [thread](https://stackoverflow.com/questions/23731876/timeout-expired-the-timeout-period-elapsed-prior-to-obtaining-a-connection-from) – Imran Sep 01 '22 at 06:15