ADO.Net best practice - Single vs multiple Connections when making asynchronous db calls

筅森魡賤 提交于 2019-12-06 04:15:52

Some time ago we faced this issue and chose to handle a separate connection object to each of the concurrent commands. It was an application making a lot of use of the database (for each page there were around 40 queries executed). We saw this was very slow because of the connection creation.

So, we changed it to a single connection (a singleton) used by every command executed. This fixed the issue and we were happy to see the application was responding faster. However, the application began growing and the need of transactions was urgent, but we faced the problem that this was not possible in our model. We ended using a mix: whenever the connection needed transactions we created a new one, if no transactions were needed then we reused the one that had been created in the singleton.

What i would do now is to use a single connection and use a transaction pattern inside the stored procedures called; avoiding having to handle the transaction on the application server.

Hope it was helpful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!