Search code examples
visual-foxpro

OleDbException Cannot open file dbf


After I run a query, SELECT SomeColumn FROM SomeTable, via the command window in VFP, I'm unable to access that table from C# using the OleDb Provider until I close VFP.

System.Data.OleDb.OleDbException: 'Cannot open file \\some-server\some-share\SomeTable.dbf.'

It's like VFP is not closing the file handle after executing the query.

How do tell VFP to close the file/table w/o having to close VFP?


Solution

  • use
    

    without any argument closes the table\cursor in current work area.

    use in (select('SomeTable'))
    

    closes it in any work area, only if it is open.

    Both commands are scoped to current data session. If you are using any sessions other than the default one, then you need to loop those sessions and close in there.

    An easier way would be to execute:

    set exclusive off
    

    in VFP before opening any tables. Then the tables would be opened shared, and you could open them both from VFP and outside.

    Or make that a permanent setting by going to Tools -> Options -> Data and unchecking "Open Exclusive": options screenshot

    BTW, I replied thinking about any table that you would open by using "use" or "select ... from thatTable".

    Your question is vague though, maybe you mean the table is created as a result of the query (your query doesn't have that destination though). If that is the case, then the created table is in exclusive use until you close it (using one the commands at top).