Thread: [Cppcms-users] How to reconnect to MySQL
Brought to you by:
artyom-beilis
From: 陈抒 <csf...@gm...> - 2011-12-05 16:04:15
|
Hello, My web site's DB connection broke because of timeout. My web site is developed in China,but MySQL server is running in the USA. I got one error log: 2011-12-05 15:43:02 GMT; cppcms, error: Caught exception [cppdb::mysql::Lost connection to MySQL server during query] (http_context.cpp:150) I have used reconnect property already: stringstream stream; stream<<"mysql:host="<<config.mysql_ip<<";database="<<config.mysql_db_name<<";user="<<config.mysql_user<<";password="<<config.mysql_password<<";@pool_size=20;set_charset_name=utf8; opt_reconnect=1"; But it didn't work. How should I do? Catch exception and call cppdb::connections_manager::gc() ? 陈抒 Best regards http://blog.csdn.net/sheismylife |
From: Artyom B. <art...@ya...> - 2011-12-05 20:11:02
|
Hello, I had checked it and yes indeed, there is a problem. The opt_reconnect does not work as prepared statements do not survive connection lost. It works with @use_prepared=off and opt_reconnect=1 but of course it has performance penalty as you loose all advantages of CppDB prepared statements caching. If the connection is lost due to timeout then probably you can change @pool_max_idle to smaller value (default is 600 i.e. 10 minutes) > > But it didn't work. How should I do? Catch exception > and call cppdb::connections_manager::gc() ? > Currently this is only option that works. Also notice that you need to call it **after** connection is closed: try { cppdb::session sql(...) }catch(cppdb::cppdb_error const &) { cppdb::connections_manager::instance().gc(); throw; } I'll look on it deeply ASAP, but it is not something simple to fix. I had opened a ticket: https://sourceforge.net/tracker/?func=detail&aid=3451653&group_id=209965&atid=1011835 Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ >________________________________ > From: 陈抒 <csf...@gm...> > > >Hello, > My web site's DB connection broke because of timeout. My web site is developed in China,but MySQL server is running in the USA. I got one error log: >2011-12-05 15:43:02 GMT; cppcms, error: Caught exception [cppdb::mysql::Lost connection to MySQL server during query] > (http_context.cpp:150) > > > I have used reconnect property already: > stringstream stream; > stream<<"mysql:host="<<config.mysql_ip<<";database="<<config.mysql_db_name<<";user="<<config.mysql_user<<";password="<<config.mysql_password<<";@pool_size=20;set_charset_name=utf8;opt_reconnect=1"; > > > >陈抒 >Best regards >http://blog.csdn.net/sheismylife > >------------------------------------------------------------------------------ >All the data continuously generated in your IT infrastructure >contains a definitive record of customers, application performance, >security threats, fraudulent activity, and more. Splunk takes this >data and makes sense of it. IT sense. And common sense. >http://p.sf.net/sfu/splunk-novd2d >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
From: Artyom B. <art...@ya...> - 2011-12-05 20:16:30
|
> > The opt_reconnect does not work as prepared statements do not survive connection > lost. > Another possible way to solve this problem is to clear prepared statements cache in case of error. cppdb::session sql(...) try { sql << ... }catch(cppdb::cppdb_error const &) { sql.clear_cache(); throw; } This would work with opt_reconnect=1, but yet it is a workaround. Artyom |
From: Artyom B. <art...@ya...> - 2011-12-21 22:49:16
|
Fixed in trunk of cppdb. Now if exception is thrown during use of a connection the connection is not recycled. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ >________________________________ > From: 陈抒 <csf...@gm...> >To: cpp...@li... >Sent: Monday, December 5, 2011 6:03 PM >Subject: [Cppcms-users] How to reconnect to MySQL > > >Hello, > My web site's DB connection broke because of timeout. My web site is developed in China,but MySQL server is running in the USA. I got one error log: >2011-12-05 15:43:02 GMT; cppcms, error: Caught exception [cppdb::mysql::Lost connection to MySQL server during query] > (http_context.cpp:150) > > > I have used reconnect property already: > stringstream stream; > stream<<"mysql:host="<<config.mysql_ip<<";database="<<config.mysql_db_name<<";user="<<config.mysql_user<<";password="<<config.mysql_password<<";@pool_size=20;set_charset_name=utf8;opt_reconnect=1"; > > > But it didn't work. How should I do? Catch exception and call cppdb::connections_manager::gc() ? > > >陈抒 >Best regards >http://blog.csdn.net/sheismylife > >------------------------------------------------------------------------------ >All the data continuously generated in your IT infrastructure >contains a definitive record of customers, application performance, >security threats, fraudulent activity, and more. Splunk takes this >data and makes sense of it. IT sense. And common sense. >http://p.sf.net/sfu/splunk-novd2d >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
From: 陈抒 <csf...@gm...> - 2011-12-22 00:44:16
|
Thanks. 陈抒 Best regards http://blog.csdn.net/sheismylife On Thu, Dec 22, 2011 at 6:49 AM, Artyom Beilis <art...@ya...> wrote: > Fixed in trunk of cppdb. Now if exception is thrown during use of a > connection > the connection is not recycled. > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.sf.net/ > CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ > > ------------------------------ > *From:* 陈抒 <csf...@gm...> > *To:* cpp...@li... > *Sent:* Monday, December 5, 2011 6:03 PM > *Subject:* [Cppcms-users] How to reconnect to MySQL > > Hello, > My web site's DB connection broke because of timeout. My web site is > developed in China,but MySQL server is running in the USA. I got one error > log: > 2011-12-05 15:43:02 GMT; cppcms, error: Caught exception > [cppdb::mysql::Lost connection to MySQL server during query] > (http_context.cpp:150) > > I have used reconnect property already: > stringstream stream; > > stream<<"mysql:host="<<config.mysql_ip<<";database="<<config.mysql_db_name<<";user="<<config.mysql_user<<";password="<<config.mysql_password<<";@pool_size=20;set_charset_name=utf8; > opt_reconnect=1"; > > But it didn't work. How should I do? Catch exception and call > cppdb::connections_manager::gc() ? > > > 陈抒 > Best regards > http://blog.csdn.net/sheismylife > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > Write once. Port to many. > Get the SDK and tools to simplify cross-platform app development. Create > new or port existing apps to sell to consumers worldwide. Explore the > Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join > http://p.sf.net/sfu/intel-appdev > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |