Problem : “File must be opened exclusively” message from an INDEX command

Problem : “File must be opened exclusively” message from an INDEX command

I have an application which I am (at last) converting from FoxPro 2.6 (and Clipper) to Visual FoxPro 6. Don’t laugh – it’s been working very happily up to now and it’s been easier to carry on with the old DOS version.

The application has some reference data that’s held in a file, where I need to be able to use tthe same file in both versions. The ‘old’ DOS version uses a series of separate index files. I’ve replaced these in the VFP version with a compound index, but I’ve used a non-structural index to avoid problems with opening the data file in the ‘old’ version.

Being a deeply-suspicious person, when I open the data file and the index in the ‘new’ version, I check to make certain that all of the TAGs that I expect to be there are indeed present. If they’re not there, then I recreate the missing ones using a command along the lines of

INDEX ON … TAG … OF … ADDITIVE

But … when I come to run this within the compiled version of the new application, I get an error message, saying

File must be opened exclusively

There’s nothing in the help pages that indicates that the INDEX ON command can only be applied to files that have been opened in EXCLUSIVE mode. (I’ve got SET EXCLUSIVE OFF in the main program, because the application is intended to operate in a multi-user environment.) The only references to this error message in the EE database concern the PACK command – and I can see why this needs to run on an EXCLUSIVE data file.

Why am I getting this error message from the INDEX ON command, and what changes should I make so as to get round it?


Solution : “File must be opened exclusively” message from an INDEX command

USE file EXCLUSIVE
INDEX ON field1 TAG field1
INDEX ON field2 TAG field2
USE

I suggest to create the indeces like above once and then run the application normally. You need to have a reindex or index recreation utility in the package but it needs to open the files exclusively.