logo       

Re: Loose Connection: msg#00037

db.mysql.c++

Subject: Re: Loose Connection

[...]
>..., but the problem is that my connection
>only persists within the constructor of this class. After that it just
>doesn't exists.
[...]
>I send complete code, because i'm a newbie in c++ and i don't know if
>i've any mistake in that...

I'm also quite starting in C++ und mysql, but I think you're right. Your
error is, that you only create a temporary object in your constructor.

You may either try to declare a member variable like

Connection con; // automatically creates object in "stack"-memory
~>calls its constructor
in your class-header
use it like befor by .operator , just let out the line
Connection con (use exceptions);

( I'm not quit shure about th "use exceptions" ... )

or maybe better, but a little more tricky use a pointer. ok, i'm quite a
newbe, but some "hacker's" may correct my code:

// in header of the class:
class xy
{
Connection* con; // say: there is a Variable reserved to save Pointer
to a connection, nothing more!
}
// let's say in "cpp-file"
// - Konstruktor
xy::xy()
{
...
this->con = new Connection; // this creates the object in
"heap"-memory ~> NOW calls its constructor
con->connect( ......... ); // -> instead of .
}
// ~ destuctor
~xy::xy()
{
delete con; // destoys Object in "heap" memory
}

I hope, these are some usefull hints for you!

(Sorry about the quoting and thread, i answered from the mailing-list-archiv
http://lists.mysql.com/ )

--
Franz Alt,

programmer and webmaster
www.mi-pfaffenhofen.de
www.bwl.wiso.tu-muenchen.de
www.tcw.de
www.tcwk.de
www.jugendparlament-paf.de
www.fatfugo.de
www.alt-rohrbach.de/internet





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise