We had a similar issue where we are using two databases. We would do some work on the first database, then run very long-running processes against the second database, then when we tried to use the first database again, the connection had died.
We resolved this using the mysqli.reconnect setting in php.ini - if you don't have access to that, you can add it to your settings.php (http://drupalyou can add it to your settings.org/node/975122php). There are some caveats with this setting (see http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.htmlThere are some caveats with this setting), such as transactions being partially completed, but these will probably not be relevant to your setup.