Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reopen table as EXCLUSIVE

Status
Not open for further replies.

justamistere

Programmer
Jul 25, 2002
67
US
This seems simple, any suggstions appreciated.
On the cmdExit.Clicked() event, I would like to try to re-open the table as "EXCLUSIVE", with the same alias name. Then reindex-tags if table can be opened exclusively.

I have tried capturing error() 1705 and 3. The "USE DBF() EXCLUSIVE" command closed the shared file, so bound controls complained.

The table is opened as "SHARED" in the public datasession=1, then =CURSORSETPROP("Buffering", 3, .gcAlias) is issued.

This app is a single form based executable, using a free .dbf table.
 
You must close the tables,
Set exclusive ON
and then open the tables again.

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
TeknoSDS,
Not necessarily. You can USE the table EXCLUSIVE in a single statement.

justamistere,
Maybe try something like copying the structure to a temp table with one record. Changing the controlsource or recordsource of the bound objects to the temp table, opening the the original table exclusive, reindex, change the bound objects, erase temp table. Hmmm. Sounds like some work.

SELECT cOrigTable
SCATTER MEMVAR
COPY STRUCTURE TO cTempTable
USE cTempTable IN 0
INSERT INTO cTmpTable FROM MEMVAR
ThisForm.SetAll("DynamicCurrentControl", ;
"cTempTable","TextBox")
USE DBF() EXCLUSIVE
DELETE TAG ALL
INDEX ON.....
INDEX ON.....
ThisForm.SetAll("DynamicCurrentControl", ;
"cOrigTable","TextBox")
USE IN cTempTable

I'm unsure about the syntax of Setall, but you may at least get an idea here.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
How is this commonly done?

I only want to test(..CAPTURE AN ERROR) if I can open the table in EXCLUSIVE mode instead of SHARED in order to rebuild index tags, only-if no other user has it open.

Yes, USE TABLE "MyAlias" ALIAS "MyAlias" EXCLUSIVE produces an error that I captured in the form's ERROR() method. Error #63 "Alias name already in use"

-Just a Mr. E.
 
You've identified all the issues:
If you re-open the table, it must be closed: this can be done explicitly:
SELECT mytable
USE
USE MyTable EXCL

or implicitly:
SELECT mytable
USE MyTable EXCL
or:
USE MyTable IN (select('MyTable')) EXCL

in all these cases, MyTable gets closed, then reopened.

This means that all bound controls will lose their bindings... so, you can just reconnect them when you're done:
THISFORM.txtOne.ControlSource = "MyTable.FieldOne"
etc...

There is no other way execpt for the bound controls to not exist when the table gets closed and reopened:
Code:
Launch main.PRG
  DO WHILE .T.
    Launch main form... when form closes, CLEAR EVENTS
    READ EVENTS
    if we should try to reindex, close/reopen table
    do reindex
    if we shouldn't exit yet, do nothing...
    if we should be exiting:
      EXIT
    endif
  ENDDO
 
Thanks WGCS.
I do not use any prg file for this one. I should've known that USE...EXCLUSIVE, actually closes the file first. Anyway when I try to use it EXCLUSIVE and another user is using it as SHARED, I capture the error and then open it again as SHARED.

In that short instance of CLOSE/OPEN-Exclusive/OPEN-Shared, before calling the .Release() Method, the controls don't complain.

If an elegant solution is not found... ...use what works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top