Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is table already open under diff alias?
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01448039
Message ID:
01448064
Views:
57
>>>>>Hi,
>>>>>
>>>>>The only way I know how to determine if a table is already open under some unknown alias is by trying to open the table exclusive and catching the error. Is there another way, maybe simpler?
>>>>>
>>>>>TIA.
>>>>
>>>>
>>>>TRY
>>>>  USE YourTable IN 0 EXCLUSIVE
>>>>CATCH
>>>>  MessageBox("The Table is already opened somewhere")
>>>>ENDTRY
>>>>
>>>
>>>Thank you, Borislav. This works but I forgot to mention that I am trying to find out if the file/table is open by "this" user and not by anyone. That is, if another user of this application has this file open (maybe on another computer), the above code will say that the file is already open. But to me this is not important; I need to find out if this datasession has the file open. Do you see what I mean?
>>
>>
>>lnUsedFiles = AUSED(laUsed)
>>lbAlreadyUsed = .f.
>>FOR lnFor = 1 TO m.lnUsedFiles
>>    IF UPPER(JUSTFNAME(DBF(laUsed[lnFor]))) = "THENAMEOFTHEDBF.DBF"
>>       lbAlreadyUsed = .t.
>>       EXIT
>>    ENDIF
>>NEXT
>>IF m.lbAlreadyUsed
>>   MessageBox("The Table is used  in this datasesion")
>>ENDIF
>>
>>
>
>I thought the above would work but it does not. The problem is that I could have the table opened under a different alias loaded in AUSED(). And then I am trying to see if the table is open. For example, if a table MyTable.dbf is open in this datasession under alias MyTable1_Alias and then I am trying to determine if the table MyTable.dbf is open, the above approach would show that NO. But in fact it is open.

I don't understand why Boris' approach is not going to work. I actually wanted to suggest exactly the same approach. You check if the table is opened based on the fullname and path of the table, so it doesn't really matter under which alias the table is opened.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform