Question

I'm having trouble getting a certain table to open up in more then one instance of my program. Whats happening is I'm trying to allow users to open up and replace a current table(part of a data dictionary - FileForm.ImagesTable) with an older table (not included in the data dictionary). It works great for one instance of the program but when we try to open up that same file simultaneously on another instance. I get the following error.

FileName.ADT This file is in use. Enter a new name or close the file that's open in another program.

Below is the code I have reassigning the table name and datapath to the selected table.

OpenDialog1.FileName := '*.adt';
OpenDialog1.Filter := 'Software 6.0 Files (*.adt)|*.adt|Software 5.x Files (*.dbf)|*.dbf';
OpenDialog1.InitialDir := DataPath;
if OpenDialog1.Execute then
begin
    Str1 := Trim(OpenDialog1.FileName);
    if Length(Str1) = 0 then
        Exit;
    DSImage.Enabled := False;

    with FileForm.ImagesTable do
    begin
        Active := False;
        AfterOpen := FileForm.TableOther.AfterOpen;
        DataBaseName := ExtractFilePath(Str1);   
        TableName :=  ExtractFileName(Str1);
        Active := True;
    end;
 end;

Edit * Using Advtantage 8.1, Seems to be a windows error because the error happens in the dialogue window. And yes Exclusive is set to false.

error


Any thougths on why this is happening and how this could be resolved are appreciated.

Thanks

Was it helpful?

Solution

It looks like you are only using the Open Dialog to get the name of the table.
On the Open dialog try setting the option ofShareAware

OpenDialog1.Options := OpenDialog1.Options + [ ofShareAware ];

Once the table is open with Advantage the mode is both deny write, deny read and as a result will return a sharing error if anything non-advantage tries to open the table.

OTHER TIPS

You're not clear on the specific error - is it a Windows error or an Advantage error?

If it's a Windows error, it may be because you've specified exclusive access to the table (ImageTable.Exclusive = True). This would mean that the first instance of the app could open it, but subsequent tries would fail with a File is in use error.

If it's an Advantage error, the Advantage help file (here in v11's documentation, since you didn't specify a version of ADS - note it's in a frame, so you may need to use this link, navigate to Advantage Developers Guide, expand the Part 1->Chapter 4 - Dictionaries->Understanding Dictionaries topic) says:

A data dictionary is a special file that serves as the sole access point for database tables

Note the sole access point. Once a table is in the data dictionary, it belongs to the data dictionary. You're trying to replace that reference with something outside the scope of the dictionary, and that isn't allowed. I'm pretty sure that the problem is related to that - ADS puts a proprietary lock on tables that are included in the dictionary, and controls access to those files through the server by way of the dictionary.

You'll need to either remove the table from the dictionary and use it as a free table, or come up with a different strategy for removing the current data and replacing it with other data to preserve the integrity of the dictionary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top