Page 1 of 1

Open database in thread ?

Posted: Wed Oct 11, 2023 2:24 am
by Victorio
Hi,
I have this problem, after some database operations (mixed DBF CDX and SQL) and database is Visual Foxpro , stay one DBF with CDX open.
But when I put Close all, and test if any database is open not see any DBF opened.

This look, to database is opened in some other thread, which I not see from main program...

When I want delete database from disc, cannot, only when I close program.

How can I close database in all threads ?

Re: Open database in thread ?

Posted: Wed Oct 11, 2023 2:37 am
by Tom
How can I close database in all threads ?
Close them in the threads. Put a DbCloseAll() just right before the "RETURN".

Another way would be to transfer the tables from the workspace of the thread to the "zerospace" and collect them from there in the main thread. DbRelease() and DbRequest() can do this. But why? Just close your tables before returning from the threads.

Re: Open database in thread ?

Posted: Wed Oct 11, 2023 3:10 am
by Victorio
Hi Tom,

In individual functions, I have closing databases either Close alias or Close all
Even in the function, after closing which the database on the disk remains blocked, I have Close all, DBCloseall(), but still after closing it, but if the main program remains on, the DBF and CDX files on the disk remain open,
If I test whether they are open via ALIAS or USED(), the program reports that they are not open, so I think that in the complex structure of the program the database somehow remained open twice, e.g. via SELECT 30, but I no longer have access to this Thread, or it is open somewhere in the background, but I can't figure out how to close it.
It IS possible that it was blocked by the SQL system (I use SQLExpress++ from Boris Borzic), because I open this database both via DBFCDX and via the ODBC Driver.
The problem is that I can't find out what blocks the DBF, CDX files on the disk. If I close the program, they are unblocked.

Re: Open database in thread ?

Posted: Wed Oct 11, 2023 4:18 am
by Tom
Hi, Victorio.

Sometimes, closing tables fails for some reasons. The main reason is open relations, but sometimes, closing tables even fails because of record locks, some kind of scopes or other reasons. But: The runtime error system raises a "Table cannot be closed" error in that situation. Maybe you replaced the standard error system, so you don't get this error. Anyway, travelling through the WorkSpaceList(), releasing all relations, releasing all locks and closing all tables step by step (check if closed with "Used()" or other functions) should remove this problem. I remember Roger wrote a function for this long time ago. I have my own, so I don't remember the function name.

Re: Open database in thread ?

Posted: Wed Oct 11, 2023 5:10 am
by Wolfgang Ciriack
I think, Roger integrated the releasing all relations, releasing all locks in DC_DbCloseArea() .and. DC_DbCloseAll().

Re: Open database in thread ?

Posted: Wed Oct 11, 2023 5:20 am
by Victorio
Thanks for thanks for trying to help,
now I found problem !
because database is not open by standard DBF (via DBFCDX), everything pointed to a SQL problem.

When I closing connections with oConnection:destroy(), database was still blocked

When put oConnection:DestroyContext(), dbf was released, and cannot delete it.
That solved :dance:

Have a nice day,
Viktor

PS: when you use SQLExpress++, description for DestroyContext :
Kills all connections that were created in current thread. By default a codeblock that calls this method is automatically assigned to the current thread's :atEnd ivar when the ivar is empty. This ensures that all connections (and statements created on that connection) are properly destroyed at thread termination.

Re: Open database in thread ?

Posted: Wed Oct 11, 2023 5:29 am
by Victorio
edit:
When put oConnection:DestroyContext(), dbf was released, and can delete it.
That solved :dance: