简体   繁体   中英

Connection Pooling in .NET

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 pooling 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM