[TurboGears] Re: Reconnect to the database (mysql) when connection goes stale
Hi Liza, Glad to hear that your project has gone well! If it's going to be publicly available, I'm sure we'd all love to hear more about it when it launches. If this is a MySQL-related issue, I wonder if it would make sense to change SQLObject's MysqlConnection to detect if the underlying DBAPI connection has gone away and do something about it. The concern I'd have there is you'd get really weird behavior if the connection goes away while you're in the middle of a transaction. TurboGears knows if you're using a transaction or not, so we might be able to make a more intelligent decision about it in turbogears.database. I've seen the MySQL connection drops previously when using Java, though I think the Java JDBC driver for mysql had an ?autoReconnect option. Kevin On 11/17/05, Liza [EMAIL PROTECTED] wrote: Hi everyone! I'm about to release an alpha version of my TurboGears project to a client. Working with the framework has been a complete joy and my coworkers are amazed at how quickly I've been able to do the development. I have one small item I need to fix before I can let the client loose: my MySQL connection goes stale due to inactivity every night. I've read the relevant questions on the SQLObject list [1] but those posts are pretty old and I can't figure out how to apply those solutions in a TurboGears context. Has anyone else encountered this issue and dealt with it? Thanks! --Liza [1] http://webwareforpython.org/archives/message/20040422.153550.0d00297e.en.html -- Liza Daly Senior Software Engineer http://www.ifactory.com/ -- Kevin Dangoor Author of the Zesty News RSS newsreader email: [EMAIL PROTECTED] company: http://www.BlazingThings.com blog: http://www.BlueSkyOnMars.com
[TurboGears] Re: Reconnect to the database (mysql) when connection goes stale
I've been getting the raw connection from the hub (via hub.getConnection().getConnection()) and invoking ping() in actions before using the database; if the connection is no longer in place, it will reconnect with the last provided connection settings. From MySQLdb.connections: | ping(...) | Checks whether or not the connection to the server is | working. If it has gone down, an automatic reconnection is | attempted. | | This function can be used by clients that remain idle for a | long while, to check whether or not the server has closed the | connection and reconnect if necessary. | | Non-standard.(The code's that running is based on the 0.5 AutoConnectHub; apologies if things have changed in that arena...!)Roger
[TurboGears] Re: Reconnect to the database (mysql) when connection goes stale
Sounds like a good thing to build in, because I'm sure you're not the only one who will need it. You haven't had any weirdness with transactions? Kevin On 11/17/05, Roger Espinosa [EMAIL PROTECTED] wrote: I've been getting the raw connection from the hub (via hub.getConnection().getConnection()) and invoking ping() in actions before using the database; if the connection is no longer in place, it will reconnect with the last provided connection settings. From MySQLdb.connections: | ping(...) | Checks whether or not the connection to the server is | working. If it has gone down, an automatic reconnection is | attempted. | | This function can be used by clients that remain idle for a | long while, to check whether or not the server has closed the | connection and reconnect if necessary. | | Non-standard. (The code's that running is based on the 0.5 AutoConnectHub; apologies if things have changed in that arena...!) Roger -- Kevin Dangoor Author of the Zesty News RSS newsreader email: [EMAIL PROTECTED] company: http://www.BlazingThings.com blog: http://www.BlueSkyOnMars.com
[TurboGears] Re: Reconnect to the database (mysql) when connection goes stale
On 11/17/05, Roger Espinosa [EMAIL PROTECTED] wrote: I've been getting the raw connection from the hub (via hub.getConnection().getConnection()) and invoking ping() in actions before using the database; if the connection is no longer in place, it will reconnect with the last provided connection settings. Great, I've stuffed this into my application and hopefully it will do the trick. Thanks very much! I'd love to share the project but unfortunately it's a back-end application. I'm not quite brave enough to deploy alpha software on a public-facing commercial site. :) --Liza
[TurboGears] Re: Reconnect to the database (mysql) when connection goes stale
On 11/17/05, Kevin Dangoor [EMAIL PROTECTED] wrote: Sounds like a good thing to build in, because I'm sure you're not theonly one who will need it.It really turned out to be a red herring for me (this was in my how completely do I not understand threading? week). How do other databases handle this? I got the idea from Apache::DBI, which pings any cached database handlers before invoking your method. You haven't had any weirdness with transactions?Can't say --- so far, this application is strictly read-only and I'm not using SQLObject for anything other than the connection. If I were writing, the ping would happen before I started the transaction (this is me, falling in the let me control my own transactions, thank you camp ;-) Roger