using System.Threading; using System.Threading.Tasks; public class DatabaseManager { private SemaphoreSlim _semaphore; public DatabaseManager(int maxConnections) { _semaphore = new SemaphoreSlim(maxConnections, maxConnections); } public async TaskIn this code, we first create a SemaphoreSlim object with a maximum count of maxConnections. Then, whenever ExecuteNonQueryAsync is called, we try to acquire the semaphore using WaitAsync. When the operation is complete, we release the semaphore using the Release method. The package library for SemaphoreSlim is "System.Threading".ExecuteNonQueryAsync(string sql) { await _semaphore.WaitAsync(); try { // execute SQL and return affected rows } finally { _semaphore.Release(); } } }