Re: How do I get the session state (and then reconnect)?
Hi!
Your best option is to use the Client class (pool implementation) and get the session just when you need it. It will keep the session open (see client timeout options) and, when getting the session, it will check if the connection is still open and, if not, do a new connection.
Here is a sample:
ClientSettings settings(SessionOption::HOST,"my_host",
SessionOption::PORT, 33060,
SessionOption::USER, "my_user"
);
Client client(settings);
for(int i=0; i<10; ++i)
{
Session s(client);
SqlResult res = s.sql("select @@version").execute();
for(auto row : res)
{
std::cout << row[0] << std::endl;
}
//This will timeout the session (controlled by mysqlx_wait_timeout server variable)
std::this_thread::sleep_for(std::chrono::hours(12));
}
Hope this helps!
Cheers,
Luís Silva
Subject
Views
Written By
Posted
859
June 20, 2021 08:36AM
Re: How do I get the session state (and then reconnect)?
460
June 21, 2021 08:57AM
507
June 21, 2021 12:01PM
592
June 22, 2021 03:02AM
395
June 22, 2021 02:05PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.