I have the following code to check if a table exists:
var selectQuery = $"SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{tableName}'";
using (var conn = new SqlConnection(_sqlServerConnectionString.SqlServerConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(selectQuery, conn))
{
var result = (int)cmd.ExecuteScalar();
return result > 0;
}
conn.Close();
}
this is called multiple times. On running this, I see:
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.
What am I missing? I have closed connection so not sure what's missing?