'Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool issues even If I used using statement

I am working on dotnet core 3.1. I am working on API call.

When I call the API, below function in Repository will execute first by saving the data:

enter image description here

then another function will get execute by getting all saved data

enter image description here

Result of this API call I have got below:

enter image description here

However using statement will prevent these kind of issues but even If I used using statement though I have getting these issues.



Solution 1:[1]

wrap in sql connection. this is example

using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]))
                    {
                        conn.Open();

using (SqlCommand cmd1 = new SqlCommand($"truncate table tablename", conn))
                        {
                            dr = cmd1.ExecuteReader();
                        }
                        dr.Close();

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Power Mouse