[Mono-list] MySql pooling, correct way of doing it

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Thu Jun 14 00:48:21 UTC 2012


On Wed, Jun 13, 2012 at 8:28 PM, Amorphiell
<philippe.grohrock at googlemail.com> wrote:
> Hello, I'm currently writing an application that needs regular, but not
> steady connection to a database. I can't provide final numbers, but I think
> my first versions will have an access of around 1 query per minute (per
> user) and if I implement more function to the program it will go up to like
> 1 query per second (per user). After reading up a bit I /think /that
> connection pooling will be the solution to go with. Now I just got a few
> questions regarding this.
>
> 1. First of all, should I really use pooling or is opening/closing a
> connection to the server each time I make a read request not that bad at
> all, performance wise. Maybe I could manually hold back write requests and
> then send them all at once.

Use pooling unless you have a reason to want to establish a new
connection every time you want to run a SQL statement.

>
> 2. In case I use pooling, how does it work? Assume that the following is my
> connection string:
> string connection =
>                "Server=localhost;"+
>                "Database=database;"+
>                "USER ID=root;"+
>                "Password=root;"+
>                "Pooling=false";
>
> On a C# site I read that using the following will yield the correct result:
> using (IDbConnection dbcon = new MySqlConnection(connection))
> {
>     dbcon.Open();
> }
>
> Then again there is the option to just use "Pooling=true", but how will that
> work? Does the pool automatically get created based on server/db/user?

Check other pooling related options at http://connectionstrings.com/mysql

Connections are pooled based on the contents of the connection string.
Same content == same pool.

Once pooling is enabled, is you open a connection, issue some
statements, and then close it, the connection will remain open in the
connection pool. This way, the next time you call "dbcon.Open ()" you
will reuse it instead of wasting time setting up the connection and
its parameters.

-Gonzalo


More information about the Mono-list mailing list