phnx47 / dapper-repositories

CRUD for Dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connection Pool

icymaru opened this issue · comments

I received this error when we tried to load test our app (web API), that uses this library. Is there a work around for this?
I think the issue is that the connections are not being closed until the end of the request. So if a single API request calls multiple repositories, multiple DB connections will be opened also, and those connections will only close at the end of the request.

System.InvalidOperationException: 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 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at MicroOrm.Dapper.Repositories.DbContext.DapperDbContext.OpenConnection() at MicroOrm.Dapper.Repositories.DbContext.DapperDbContext.get_Connection()

commented

sql-server-connection-pooling
It seems that you need to close it manually or it will not close for a while.
And it may open all the time if some exception happened(the program skip the 'close()' function ),then you will have no connection to use before long.