Partager via


Error Reading File infinite loop if drive disabled while file open and Data Session window open

If you have a file open on some drive (perhaps a USB or network drive) and the Data Session window open, try disconnecting the drive somehow. Perhaps yank the network cable, pull the USB drive even though Windows says not to, or even move out of wireless range.

Change the filename below to refer to that drive and run this code:

CLEAR ALL

CLEAR

cTable="e:\test.dbf"

SET && activate data session window

IF !FILE(ctable)

          CREATE TABLE (cTable) (name c(10))

          INSERT INTO test VALUES ("one")

          INSERT INTO test VALUES ("two")

ENDIF

USE (cTable) SHARED

LIST

MESSAGEBOX("Remove or disable drive now")

LIST

I get an error message: Error reading file e:\test.dbf.

When dismissed, the error recurs ad infinitum, allowing no chance for me to close the file. The only thing I can do is terminate the process.

Have you ever run into this one?

The Data Session window is periodically trying to refresh itself. It displays the various tables in use, the number of records and the workarea of the current cursor. When an error occurs, it reports it. Then it repeats.

A simple fix: catch the error and don’t do anything. If the use subsequently tries to read from the table using some other operation, then the error will recur then.

Moral: when processing a periodic event, be careful about reporting errors.

History: the Data Session window used to be called the View window, and in fact the routines are called ViewNull and DrawView. Parts of this code probably date back to FoxBase days over 15 years ago!

See also Why can't I browse my table?