Closed MagicXran closed 1 year ago
In order to maximize usage, I will execute multiple sql on the same connection. Please tell me, is this possible, or are there any better improvement measures? thanks!
// initialize ocilib::Pool pool
function (ocilib::Pool pool)
{
auto conn = pool.getConnection();
ocilib::Statement stmt(conn);
if(condition)
{
try
{
stmt.Execute(sql);
conn.Commit();
}
catch (...)
{
conn.Rollback();
std::cerr << "Error in " << EventName << std::endl;
}
}
// Use the same connection
try
{
stmt.Execute(sql2);
conn.Commit();
}
catch (...)
{
conn.Rollback();
std::cerr << "Error in " << EventName << std::endl;
}
//.....
Hi,
As soon the connection object is out of scope (destructor invoked) and if there is no more reference to the underlying handle, the oracle connection is returned to the pool automatically. Calling connection::Close() does the same ( in fact the destructor calls Close()).
By default, in case of exhausted pool, Pool::GetConnection() is a blocking call until a connection is available (this behaviour can be changed using Pool::SetNoWait()).
Regards,
Vincent
If Pool::SetNoWait(TRUE), what happens when the connection resources are exhausted? Will a new connection resource be created? Or return empty? Or something else
Pool::GetConnection() will raise an exception
Excuse me, is it possible to establish two ocilib::Pool to connect to different databases respectively? Will there be conflicts?
Of course you can use different pools to connect to different databases :)
Vincent
Excuse me, I use ocilib::Pool and getConnection () every time. In this case, will the connection be automatically re-established when the resources in the connection pool are exhausted? Is it possible to use getConnection () to get a connection and automatically recycle it after use? This can avoid the shortage of resources in the connection pool and the frequent creation of links when the database is frequently operated.