开发者

Connection Pooling in .NET

开发者 https://www.devze.com 2022-12-22 07:42 出处:网络
I\'m trying to create a Database object for myself in .net.The constructor takes a connection string and opens a connection to the MySQL db using the MySQL Connector.It has functions like:

I'm trying to create a Database object for myself in .net. The constructor takes a connection string and opens a connection to the MySQL db using the MySQL Connector. It has functions like:

function executeNonQuery(cmd as String) as Boolean
function getOneResultQuery(query as String) as String
function getDataReader(query as String) as MySQLDataReader

When a task needs the db, it instantiates the database object and calls its necessary commands. When it is done with the database, it calls the disconnect() function.

Does this take advantage of MySQL Connection Pooling? As each tasks connects and disconnects from the DB (sometimes more than one connection open at a time, sometimes one connection open, sometimes no connections open) do the connections get stored in a pool? Do I have to leave one connection permanently open for connection 开发者_如何学JAVApooling to be enabled?

Is this database object a decent practice or am I overdoing this?


I'm no expert in MySql, but I know how Connection Pooling works in SQL Server, so I Googled it to see if my suspicions are correct.

According to this post, Connection pooling to MySql from .Net is similar in that if you use the same connection string (I believe that means EXACTLY the same - case-sensitive, etc) connection pooling will be automatically implemented by the framework.

If that's the case then you're over-thinking it, and maintaining an open connection is not necessary. (In most cases it's just a bad practice asking for trouble).

Based on a general understanding of how the .Net runtime extracts the details away for you, I feel confident enough in this answer to post it as an answer and not a comment.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号