Open database in thread ?

This forum is for eXpress++ general support.
Post Reply
Message
Author
Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Open database in thread ?

#1 Post 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 ?

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Open database in thread ?

#2 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Open database in thread ?

#3 Post 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.

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Open database in thread ?

#4 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Wolfgang Ciriack
Posts: 481
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Open database in thread ?

#5 Post by Wolfgang Ciriack »

I think, Roger integrated the releasing all relations, releasing all locks in DC_DbCloseArea() .and. DC_DbCloseAll().
_______________________
Best Regards
Wolfgang

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Open database in thread ?

#6 Post 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.

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Open database in thread ?

#7 Post by Victorio »

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

Post Reply