473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DB connection pool. How to pass handle?

I'm new to C++ and I need to create DB connection pool.

Here is the class that I have:
class uudb
{
public:
uudb();
~uudb();

sptk::CODBCDatabase handle;
void connect(std::string login, std::string password, int server,
std::string sessionid);
void disconnect();
};
uudb::uudb() : handle("DSN=PostgreSQL;UID=serge;PWD=;DATABASE=uu" )
{
cout<<"\nOpening DB ...\n";
handle.open();
}

uudb::~uudb()
{
cout<<"\nClosing DB ...\n";
handle.close();
}

void uudb::connect(string login, string password, int server, string
sessionid)
{

try {
CQuery loginQuery(&handle,"select
login(:login,:password,:server)");
loginQuery.param("login") = login;
loginQuery.param("password") = password;
loginQuery.param("server") = server; //
lexical_cast<string>(server);
loginQuery.exec();
cout<<"\nConnected\n";
}
catch (exception& e) {
cout<<"\nError: " <<e.what();
}

}

void uudb::disconnect()
{

try {
CQuery logoutQuery(&handle,"select logout()");
logoutQuery.exec();
cout<<"\nDisconnected\n";
}
catch (exception& e) {
cout<<"\nError: " <<e.what();
}

}

I need to pass this handle to other classes, so they can use it to
communicate with DB, but I have no idea how to do it.

Your help is appreciated.

Mar 20 '07 #1
6 2736
<se****@total-knowledge.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
I'm new to C++ and I need to create DB connection pool.

Here is the class that I have:
class uudb
{
public:
uudb();
~uudb();

sptk::CODBCDatabase handle;
void connect(std::string login, std::string password, int server,
std::string sessionid);
void disconnect();
};
uudb::uudb() : handle("DSN=PostgreSQL;UID=serge;PWD=;DATABASE=uu" )
{
cout<<"\nOpening DB ...\n";
handle.open();
}

uudb::~uudb()
{
cout<<"\nClosing DB ...\n";
handle.close();
}

void uudb::connect(string login, string password, int server, string
sessionid)
{

try {
CQuery loginQuery(&handle,"select
login(:login,:password,:server)");
loginQuery.param("login") = login;
loginQuery.param("password") = password;
loginQuery.param("server") = server; //
lexical_cast<string>(server);
loginQuery.exec();
cout<<"\nConnected\n";
}
catch (exception& e) {
cout<<"\nError: " <<e.what();
}

}

void uudb::disconnect()
{

try {
CQuery logoutQuery(&handle,"select logout()");
logoutQuery.exec();
cout<<"\nDisconnected\n";
}
catch (exception& e) {
cout<<"\nError: " <<e.what();
}

}

I need to pass this handle to other classes, so they can use it to
communicate with DB, but I have no idea how to do it.

Your help is appreciated.
The best way is probably with a reference.

sptk::CODBCDatabase& GetHandle( ) { return handle };
Mar 20 '07 #2
Thanks for your reply, it helped.

Now I need to get this handle(with all DSN parameters) in another
class located in different directory.
I tried this:

CPP / C++ / C Code:

void LoginServlet::service()
{
uudb* db = new uudb();
sptk::CODBCDatabase handle = db.getHandle();
//pass handle to DB model class operation
login(login, password, handle);
}
but with no success.
What's the right way to do it? Thanks.

Mar 20 '07 #3
<se****@total-knowledge.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Thanks for your reply, it helped.

Now I need to get this handle(with all DSN parameters) in another
class located in different directory.
I tried this:

CPP / C++ / C Code:

void LoginServlet::service()
{
uudb* db = new uudb();
sptk::CODBCDatabase handle = db.getHandle();
//pass handle to DB model class operation
login(login, password, handle);
}
but with no success.
What's the right way to do it? Thanks.
If you coded it the way I showed, it is returning a reference.

sptk::CODBCDatabase& handle = db.getHandle;
Mar 21 '07 #4
On Mar 20, 6:13 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<ser...@total-knowledge.comwrote in message

news:11**********************@y80g2000hsf.googlegr oups.com...
Thanks for your reply, it helped.
Now I need to get this handle(with all DSN parameters) in another
class located in different directory.
I tried this:
CPP / C++ / C Code:
void LoginServlet::service()
{
uudb* db = new uudb();
sptk::CODBCDatabase handle = db.getHandle();
//pass handle to DB model class operation
login(login, password, handle);
}
but with no success.
What's the right way to do it? Thanks.

If you coded it the way I showed, it is returning a reference.

sptk::CODBCDatabase& handle = db.getHandle;
You should also declare the copy constructor and overloaded assignment
operator as private so that you prevent applications from making
copies of a database handle.

Mar 21 '07 #5

"Jim Langston" <ta*******@rocketmail.comwrote in message
news:4F***************@newsfe06.lga...
<se****@total-knowledge.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
>Thanks for your reply, it helped.

Now I need to get this handle(with all DSN parameters) in another
class located in different directory.
I tried this:

CPP / C++ / C Code:

void LoginServlet::service()
{
uudb* db = new uudb();
sptk::CODBCDatabase handle = db.getHandle();
//pass handle to DB model class operation
login(login, password, handle);
}
but with no success.
What's the right way to do it? Thanks.

If you coded it the way I showed, it is returning a reference.

sptk::CODBCDatabase& handle = db.getHandle;
Ug. I hope you realize I meant
sptk::CODBCDatabase& handle = db.getHandle();

getHandle is a function.
Mar 21 '07 #6
Thanks guys, your were very helpful!

Mar 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JWM | last post by:
I am trying to implement Oracle connection pooling for the following code, which was written by someone else. Here is my main question -- this java file creates code that is executed every hour,...
7
by: greg | last post by:
Hi We have w2k, iis5, .NET/c# I periodically receive this message and the system freezes ++++++++++++++++++++++++++++++++++++++++++++++++++ Timeout expired. The timeout period elapsed...
18
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
10
by: Steven Blair | last post by:
As I understand it, if I create a connection object in my application and close the connection, the next time I open a connection with the same connection string I should be using a pooled...
16
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
5
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have a method that requires me to specify a client handle when I create the object. The object prototype is as follows... void Server.CreateMonitor(string strName, int...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.