On Tue, 1 Mar 2016 17:13:29 +0000 a a <NoCos30 at hotmail.com> wrote:
> I want to check after a while if the connection is allready closed or > not for the simple reason not to reopen the database but if is open > to run a query or if it is closed to reopen the database and then run > the query. I don't blame you for thinking that's what you want to do, but you really don't. Consider that the situation you describe has many analogs. You cannot check if a file is closed, if a socket is closed, if free(3) has been called on a pointer. More important, suppose you *could* check those things. Could the OS assure you that the file you opened, the socket, or the memory pointed to is the resource you intended? Could it say anything about the state of that resource? On both counts: No. The solution is to organize your program such that there's no question about the state of its resources. If you must have a flag then, as Keith suggests, the most common way is to set the handle to NULL after you close it. But simplest is best. It's often feasible to open the database just once at the beginning and never close it until exit. Unless you have hundreds of databases open concurrently or are working in an extremely constrained environment, the overhead of carrying around a largely unused database handle is negligible. HTH. --jkl