Share via


How to: Set Data Access

In a shared environment, you can access data in two ways: from exclusive files or from shared files. If you open a table for shared access, other users also have access to the file. If you open a table for exclusive access, no other user can read or write to that file. Because exclusive use defeats many of the benefits of sharing data on a network, it should be used sparingly.

Using a Table with Exclusive Access

The most restrictive way to open a file is to open it exclusively. When you open a table through the interface, it opens for exclusive use by default. You can also explicitly open a table for exclusive use by using Visual FoxPro commands.

To open a table for exclusive use

  • Type the following commands in the Command window:

    SET EXCLUSIVE ON
    USE cMyTable
    

    -or-

  • Type the following command in the Command window:

    USE cMyTable EXCLUSIVE
    

The following commands require you to open a table for exclusive use:

Visual FoxPro returns the error, "Exclusive open of file is required," if you try to execute one of these commands on a shared table.

You can restrict access to a table by using the FLOCK( ) Function. If you use FLOCK( ) to lock the table, other users cannot write to the table but they can read it.

Using a Table with Shared Access

When you open a table for shared use, more than one workstation can use the same table at the same time. When you open a table through the interface, you can override the default ON setting for the SET EXCLUSIVE Command. You can explicitly open a table for shared use by using Visual FoxPro commands.

To open a table for shared use

  • Type the following commands in the Command window:

    SET EXCLUSIVE OFF
    USE cMyTable
    

    -or-

  • Type the following command in the Command window:

    USE cMyTable SHARED
    

When you add or change data in a shared table, you must first lock the affected record or the entire table. You can lock a record or a table opened for shared use in the following ways:

  • Use a command that performs an automatic record or table lock.

  • Manually lock one or more records or an entire table with the record and table locking functions.

  • Initiate buffering with the CURSORSETPROP( ) Function.

Associated memo and index files always open with the same share status as their table.

If your application uses a table for lookup purposes only and all users of the application access it, then you can improve performance by marking the table as read-only.

See Also

Tasks

How to: Use Data Sessions

Reference

SET EXCLUSIVE Command

Other Resources

Controlling Access to Data

Programming for Shared Access