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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"File Access is Denied" ?? 2

Status
Not open for further replies.

alan232

Programmer
May 19, 2004
144
US
Hi All;

I've written two forms, 'ledgers' and 'Signin' in vfp 6.0. They both use the same class library call as:

if !used('__Site')
if file(_local)
use _local in 0 again alias __Site shared
else
messagebox("[csite.init] Missing system file c:\system\Loc_Site.dbf")
return .f.
endif
endif ( !used('__Site'))

Both forms use private datasessions. The above code is called in the beforeOpenTable event of the dataenvironment of the form.

My staff is in the habit of using ms windows to open signin on the desktop, and rather then closing it, simply minimizing it and then opening ledgers on the desktop. When ledgers is opened,
"if !used('__Site')" is true, and "if file(_local)" is true, but
"use _local in 0 again alias __Site shared"
completely bombs out reporting:
"File Access is Denied"

Please help anybody!
Thanks,
alan
 
File Access is Denied" usually means that somebody else has the table open exclusive. Does the signin form have a DataEnvironment that's opening that table?

By the way, is the file named "_local" or "_local.dbf"? The FILE() function needs the full name of the file.

Geoff Franklin
 
Hi alvechurchdata;

'_local' is #define _local 'c:\data\site.dbf'

Actually, I later found the problem when one of the methods had already opened site.dbf using 'exclusive'.
However, that still doesn't explain to me why the file already opened is not deteteced by 'used()' ???

Any ideas?
Thanks again,
alan
 
Hi Alan.

However, that still doesn't explain to me why the file already opened is not deteteced by 'used()' ???

You said it yourself - someone else on a different computer has the file opened exclusive.

The USED() function only looks at tables in the current data session. So even if you had the table open on your own machine in the default data session, you form with the private data session still would not know that it was USED().



Marcia G. Akins
 
Hi All;

I try to put in any particular method only the necessary lines that make one method different from another. As much work as I can give to the compiler, yet clearly express my idea in code, I do. So the #define for local. __Site is used through out the program as an alias--kindof a constant.

Thanks Marcia, appreciate the clarification on used(). Is there any vfp function that can tell me if a file is open in any datasession? Something like used()? (I keep thinking of some kind of memory search or something.)

 
Hi Alan.

Is there any vfp function that can tell me if a file is open in any datasession? Something like used()? (I keep thinking of some kind of memory search or something.)

Not that I know of. The best that you can do is to wrap this in a TRY...CATCH if there is a possibility that the table you are trying to oipen may be used exclusively by someone else.



Marcia G. Akins
 
Try an fopen() if you can get a lock the table/file is available. fclose() it and continue, otherwise do your alternative.

Brian
 
Hi All;

Thanks Marcia. I'm not sure what vfp 6.0 has to compare to try...catch, but I get your thought..maybe I can put an error routine on use()? I've not tried it yet, but baltman's idea also seems pretty straightforward, assuming fopen() bypasses the datasession question.

Thanks everybody...I think I can get it to work now.
Sincerely,
Alan
 
Thanks Marcia. I'm not sure what vfp 6.0 has to compare to try...catch, but I get your thought

Off the top of my head and untested:

Code:
FUNCTION OpenTable( tcTable, tcAlias, tlExclusive )

LOCAL lcOldOnError, lcAlias, llError  
lcOldOnError = ON( [ERROR] )
lcAlias = IIF( NOT EMPTY( tcALias ), tcAlias, JUSTSTEM( tcTable ) )
ON ERROR llError = .T.
IF USED( laALias )
  IF tlExclusive
    *** If we need to use it exlcusive
    *** and it is already used, we need to close
    *** it and try to use it exclusive
    USE IN ( lcAlias )
    USE ( tcTable ) ALIAS ( lcAlias ) EXCLUSIVE IN 0
    IF llError
      lcAlias = []
    ENDIF
  ENDIF
ELSE
  IF tlExclusive
    USE ( tcTable ) ALIAS ( lcAlias ) EXCLUSIVE IN 0
    IF llError
      lcAlias = []
    ENDIF
  ELSE
    USE ( tcTable ) ALIAS ( lcAlias ) AGAIN IN 0
  ENDIF
ENDIF
IF NOT EMPTY( lcOldOnError )
  ON ERROR &lcOldOnError
ELSE
  ON ERROR
ENDIF
RETURN lcAlias


Marcia G. Akins
 
Hi Marcia;

Thanks much for the code! I'll give it a try.

Alan
 
The great thing about fopen() is that it works on any file you want to manipulate, not just a table.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top