User1551892
User1551892

Reputation: 3364

How to increase the connection timeout for mysql connection from c# application?

I want to increase the connection timeout for mysql connection and I can not modify the timeout settings from administrator panel of mysql server. I want to do it within c# application and I noticed that I can read the property ConnectionTimeout of MySqlConnection class. I would like to know that is there a way to increase the connection time before opening mysql connection.

Upvotes: 8

Views: 47939

Answers (4)

Christian Quirós
Christian Quirós

Reputation: 504

default command timeout=0 in your connection string does the trick.

String connectionString = "Server=myserver; Port=3306; Database=databasename; Uid=userid; Pwd=password;default command timeout=0";

Upvotes: 1

Diego Ripera
Diego Ripera

Reputation: 85

use "default command timeout" in your connection string, it works for me

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
default command timeout=20;

https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/specifying-default-command-timeout/

Upvotes: 7

Chandan Kumar
Chandan Kumar

Reputation: 4638

Check out the wait_timeout parameter for my.ini

Here is the link. restart mysql after changing the value.Why, because There may be multiple my.ini's on your system - make sure you're changing the right one

 http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout

or

you can define in your connection string

String myconnstring = "Server=yourservername; Port=portno; Database=yourdatabasename; Uid=yourUSERID; Pwd=yourpassword;Connection Timeout=120";

Upvotes: 3

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

you can change ConnectionString as below:

String connectionString = "Server=myserver; Port=3306; Database=databasename; Uid=userid; Pwd=password;Connection Timeout=30";

in the above Connection String you can specify the number of seconds as value for Connection Timeout

Upvotes: 18

Related Questions