Wiki Home

Alias Name Is Session Name

Namespace: WIN_COM_API
The USE statement is failing. I get a 'File in Use' error.
    IF !USED(.TempTable)
        USE (.TempTable) IN 0 EXCL ALIAS (.TempTable)

When I go look at the situation with SET the alias name is the same as the data session name: "Default(1)". See below.
This started happening after we converted to VFP7 SP1. And sometimes the name "Default(1)" has binary characters after it! Workaround at bottom. Joe Kuhn

Sounds frustrating! I don't quite understand what's happening, though. Is there a way to programmatically retrieve the data session name? Which file is "that Fox dbf (in a dbc)"? - wgcs
The file behind the alias 'Default(1)' is shown in the talk window when I click on 'Default(1)'. Since I open it exclusively it isn't in the alias list anywhere else. Joe
Excuse me for butting in- I'm new to Wiki but have programed in Fox since 2.x for DOS. Am I understanding that you are coding something like USE CUSTOMER ALIAS CUSTOMER and the alias is being changed? Or are you doing something like USE CUSTOMER ALIAS &sessionid? Anita
In any event if it was working before you installed VFP7sp1 and now it doesn't you have to find a work around.

You could try looping through the open work areas testing for the table name in the DBF() open there. It is one way to do it as a quick 'n dirty way to get production code working ASAP, but there has to be a better way than that because it would not be very efficient. - Anita
Will probably end up doing that. It's seems to happen in the same place every time. Joe
What sort of name is .TempTable? (ie. Is there something about the format of it that may be confusing VFP, like is it a randomly generated string that used to start with letters but now starts with digits?)

It's the name of a dbf in a dbc where I store the data after reading the text file. There are lots of these dbfs, one per line type in the source. Joe
I've also had some funny behavior in VFP6 where THIS sometimes doesn't refer to the right object in an object's event code; I've never had trouble with THISFORM, though, so if this is in a form method try THISFORM instead; if this is in an object's event code, move this code to the form and call the form method. - ?wgcs

There is no form on top of this code yet. It's command line driven at the moment. Joe
How about
 USE (.TempTable) ALIAS TempTable 
? Notice I didn't include the period in the alias. That would make the alias "TempTable". Your code could be checking for IF USED("TempTable") instead. If you want to ensure the correct DBF is open, do something like...
IF USED("TempTable") AND !DBF("TempTable") == .TempTable
  USE (.TempTable) ALIAS TempTable in TempTable

-- Mike Yearwood
I open lots of these at the same time, but since I only use one of them in any give operation (hours) I could refactor and adopt your method. This would be a larger workaround than I had hoped for.

I'm noticing that it happens in the same code every time. I take this as a strong clue about where to look for a cure. I also know where to put a workaround that uses the 'DBF()' function. Joe
Here's what I ended up doing as a workaround:

IF !USED(.TempTable)
    * USED() might have failed, so go through work areas
    * looking for the dbf behind the alias
    * alias name = dbf name in this code
    lnCount = AUSED(laUsed)
    FOR lnThisEl = 1 to lnCount
        lnWorkArea = laUsed[lnThisEl, 2]
	IF ATC(.TempTable + ".DBF", DBF(lnWorkArea)) > 0
	    SELECT (lnWorkArea)
	    USE IN (lnWorkArea)
    USE (.TempTable) IN 0 EXCL ALIAS (.TempTable)

I think it's possible that the problem could have been related to extraneous spaces in the property value:

lcX = "SomeTable "
use (lcX) in 0 exclusive && file opens just fine name substitution ignores trailing spaces
? used( lcx ) && false because of the trailing space
if ( ! used( lcX ) )
   use (lcX) in 0 exclusive && throws file in use error because it is in fact used

Category Questions