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

"File is in use error" 1

Status
Not open for further replies.

Steep

Programmer
Jan 22, 2013
3
PH
Hi everyone,

I'm wondering if someone can help me with regards to "File is in Use error". Everytime this error occurs I am forced to tell the users to logout of the system and then login again to continue their work. I've used the 'set multilocks' and 'set reprocess' command and unlock the database after use can somebody help me what might be the cause or how can I detect the data that has been causing this problem.

Thanks,
Steep[bigsmile]
 
Maybe there's already locked table/record and you are locking it again?
or
Open Data Session Window(in your toolbar) to trace w/c is currently in use. if its already there and you attempted to call it again, it will prompt that message. rather than calling it again, use "SELECT" to prevent such error.

HTH
Dexter
 
thank you Dexter, i'll try your suggestion and i hope that this will solve the problem...[bigsmile]
 
Dexter is halfways on the right track. If you open a table twice on the same station and it's current datasession, this error happens, for example if you
USE sometable IN 0 twice (The IN 0 is not the important part, but if you do USE sometable twice you reopen the same table in the same workarea and therefor don't get that error, as it's still just in use once). If a lock is done the error would rather be "File is in use by another user", that's a totally different error, just starting with the same text.

So, if you don't abbreviate the real error, then your fault is to open a table twice. It actually is not imposible, as you can USE sometable AGAIN, you just also need to give it a different alias name, so USE sometable alias smetable2 AGAIN is possible, for example. But surely you won't want to make use of that, if follow up code is using the normal table name.

The error can be avoided by SELECT table instead of USE table, as Dexter says. But you typically open all tables of your form at form start, either in the dataenvironment or in Load or via any data access classes of a framework, whatever. Once tables are open you only need to SELECT table, if that's needed at all.

If you want to use some table only, if they need to be used, and a button click has USE sometable in it, then you can easily get this error, if that button is clicked for the second time. You can be lucky, if the currently selected workarea is that table it won't error, so often enough a test of clicking some button twice will not reveal this error. This is the thing, that makes this error so tricky.

It's not really a natural concept, as using a table mostly means to FOpen a dbf (and validate a header and prefetch a record, perhaps, but mostly FOpen), you don't expect this won't work. In the old days you only had 15 workareas, therefore it was an important clue, that you're reusing the same table twice. That's the historic reasoning of that error.

If that error happens because two forms open the table, make sure you separate them by letting forms use private datasessions, then you on't have that disadvantage.

Bye, Olaf.
 
Thanks OlafDoschke i hope this time i can resolve the problem...
 
Hi,

File is in use - which file? a .DBF or a.SCX or a .FRX ?
Are you working with 1 EXE on the server ?
Please be as precise as possible when you post a generic question like this.

Jockey(2)
 
The solution is proper error handling. Never let VFP simply handle an error and display the default dialog (unless there is no other option, for example C5 errors). As you can see from the error you get, that tells you nothing.

Doug Hennig has a good paper at Search for Error on the page.

You should also learn about the Error method in controls and the ON ERROR command, but it should only be used in your main program as a catch all.

Craig Berntson
MCSD, Visual C# MVP,
 
If you are using a form when getting this error simply add CLEAR WINDOW to the exit button on your form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top