Re: MySQL Connector/Net executing extra actions on database servers while running simple select statements
Posted by: Gabriela Martinez
Date: September 25, 2012 09:34AM

Hi Chin,

The SHOW variables and SHOW collation are operations that need to be done in order to load the server settings when doing a new connection to the database. You can avoid that the connector performs these operations by enabling the CacheServerProperties setting in the connection string. If you do so the driver will cache the server properties in the Pool Manager in the first connection, so the next ones will be using the same cache settings instead reading again from the server.

Example:


using (MySqlConnection c1 = new MySqlConnection("server=localhost;User Id=youruser;password=password;database=yourdatabase;port=3306;Cache Server Properties=true"))
{
c1.Open();
MySqlCommand cmd = new MySqlCommand("SELECT Count(*) from table", c1);
var count = cmd.ExecuteScalar();
//more operations...
}

You can have more information here: http://dev.mysql.com/doc/refman/5.1/en/connector-net-programming-connection-pooling.html

Or please let us know if you have any other question or comments.

Gabriela Martinez
.Net Developer on MySql Connector/net team.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.