Skip navigation links

MySQL Forums


Advanced Search

Reconnecting to the server
Posted by: Wojciech Barski ()
Date: November 12, 2008 06:56AM

How can I reconnect to a server using the same connection variable? To illustrate the problem, I have the following code:

......
mysqlpp::Connection mysqlcon(false);

mysqlcon.connect (some db, some server, some user, some pass);

...do some queries...

mysqlcon.disconnect();

.....

Now everything is working fine until I want to reuse mysqlcon to connect as another user like this:

...do some queries...

mysqlcon.disconnect();

...do some other stuff...

mysqlcon.connect(some db, some server, another user, another pass);


And this is the moment that my application crashes. Does anyone have a solution to this problem? In my program, I store mysqlcon as a global variable so I can use it in different functions. But sometimes I need to log out and reconnect as another user (I'm writing an application for a fitness centre customer service and different people log into it at the reception desk).

I figured I could maybe do this using a connection pool, but isn't there a simpler way to reuse mysqlcon to reconnect to the server?

Options: ReplyQuote


Subject Written By Posted
Reconnecting to the server Wojciech Barski 11/12/2008 06:56AM


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