How to efficiently share database connection objects from a connection pool in C #?

Hi, can someone help me find how to efficiently share database connection objects from a .net connection pool. Mine is a web application, and I should also limit the connection pool size to the number of participants (e.g. 20 connections). So requests from the entire client browser share these 20 connections. And I read that if more than 20 requests are received at the same time, the rest of the requests are forced to wait until any connection in the pool is released. can i have a better way to manage these connections? My main task is to process so many requests on a web server without overloading the database server. can someone help me ..

+4
source share
2 answers

Connections will be automatically pulled out of the pool based on the connection string, so if you do not change the connection string for each user (or other purposes), you can reuse the connection from the pool as soon as you do this with one (note that I describe the behavior that the union code performs, not what you need to do or worry about).

To succeed in this, you need to make sure that your connections are open only if you need them, and that they are always, always closed (this is general advice, and not just specific to your situation).

If you find that you are working with a connection pool limit, you can catch this error and either ask the user to try again later, or scroll for a short period of time and try the connection again.

+6
source

The default maximum pool size is 100, but if you want to reduce this number to 20, you can specify it in your connection string.

Using these parameters in the connection string:

Max Pool Size = 20 Pooling = True 

You limit the pool size to 20.

See here for ConnectionString for details .

+1
source

Source: https://habr.com/ru/post/1381836/


All Articles