Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBCMD error 2001 and DBFNTX error 1020

Status
Not open for further replies.

hardyone

Programmer
Apr 15, 2010
8
US
I am a novice Clipper programmer running a few programs for personal/office use. Several months ago I started experiencing crashes in one program.

Most commonly it is "DBCMD error 2001: Work area not in use" from ordlistcle(0). This will be at a "Set Index to <ntx> " line which follows a " Use <dbf> new ". I restart the program and it runs just fine, handling that line of code the next time without difficulty. It has happened randomly at multiple different "set index to " commands in different prg files over the last several months. In some instances I have written the code as one line: “Use <dbf> index <ntx> new” If it crashes on that line I see “DBCMD error 2001: Work area not in use” from ordlistadd() instead of ordlistcle(). (I am not really familiar with these “behind the scenes” Clipper functions of ordlistcle and ordlistadd but I can guess they are handling the index files.)

Less commonly the error is "DBFNTX 1020 Work area not indexed" from dbseek(0). This error is at a “Seek....” command following “Use <dbf> new...set index to <ntx>”. Again when I restart the program it handles that same line of code without difficulty.

I am using Clipper 5.2 with the 5.2d patch.

So what is going wrong?
 
What is happening is the file open in the use clause is failing. Consequently when trying to open the index you get the work area not in use error.

The other error is similar - in that case the open of the index file has failed, so subsequently when you try to do an index operation you get the work area not indexed response.

To know exactly why this is happening, more information is required:
- are there more than one task or users opening these files?
- are they being opened in shared mode or exclusive?
- what operating system is being used.

The way around this problem is to check for errors after using a file. For example, I use a standard function to open files either in exclusive or shared mode that looks like this:
In the calling program:
Code:
set exclusive off
if !net_use('database',.f.,5)
   ? 'Unable to get shared access to database'
   return
endif
...
Here is the net_use function:
Code:
function net_use
parameters file, ex_use, wait
private forever

forever = (wait = 0)
do while (forever .or. wait > 0)

   if ex_use                    && exclusive
      use &file exclusive
   else
      use &file                 && shared
   endif

   if .not. neterr()           && USE succeeds
      return (.t.)
   endif

   inkey(1)                     && wait 1 second
   wait = wait - 1
enddo
return (.f.)                    && USE fails

As you can see this routine will keep trying the use until either a timeout expires or it succeeds. The key thing is to check the error status after the use statement.

Why does this happen?

- other tasks may have the file open; even such tnings as virus scanners and indexing services
- due to OS disk caching or opportunistic locking (under Windows) it may take a few seconds for all outstanding activity on a recently closed file to complete, and a subsequent open may be premature.

So what you have to do is write your program as if the file is networked, even though it isn't.

Jock

 

Jock:

To answer your questions:
No other program opens these files and I am the only user.
I do not specify Shared or Exclusive. I believe Clipper opens in exclusive mode by default if no specification is made, doesn’t it?
The operating system is XP SP3

Your explanation makes sense however, even without your knowledge of those answers. It also makes sense to me that this problem came up when I started running this program on a new laptop a year ago. As you point out there must be something about the way Windows is set up on that laptop that retards file handling so the dbf file doesn’t open occasionally. Your advice is good: in the Windows environment I need to write the program as if the file is networked, even though it isn’t. I understand your workaround using the net_use function. I have done a little programming using neterr() and a time of delay waiting for a successful open.

But what about the failure of the index file to open? Do you have a way to trap and handle that error?

Thanks for your help,
Jim
 
Hi Jim

Recent Windows versions work differently than previously with legacy file and record locking applications like Clipper. The symptom you describe about the .dbf file is exactly what happens if you attempt to use a dbf file which is currently open in another window.

It is even slower on a laptop due to disk delay, especially if the drive has to spin up first or if there is a lot of disk activity. Although you are only one user you may have more than one task opening the files, as I mentioned. Your disk should be set to "always on" in power management.

I'm guessing this might also explain the DBFNTX1020, though I have not seen this happen.

Jock
 
This sounds very like an antivirus problem - with the file being scanned by the AV as you open it - thereby preventing your app from getting exclusive access.

I would use a net_use function (like the one above suggested by Jock) and separate the opening of the table from the opening of the index files, that way you can firstly ensure the table is open in the selecetd work area and then try to open the indexes - each of these may be delayed by the AV as well!



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Hi

I guess, you are trying to open too many files at one time, try modifying your autoexec.nt and config.nt, you can find these files in windows\system32 folder.

in autoexec.nt add one line in the end, SET CLIPPER=F80

in config.nt increase files=60 and one line buffers=60

reboot your laptop.

Regards
Naresh
 
If it was too many files he would get a DOS Error 4 (I think it was 4!)



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
For old times sake:
Code:
       1        Invalid function number  19        Attempt to write on
                                                 write-protected diskette
       2        File not found            20        Unknown unit
       3        Path not found            21        Drive not ready
       4        Too many open files       22        Unknown command
               (no handles left)
       5        Access denied             23        Data error (CRC)
       6        Invalid handle            24        Bad request structure length
       7        Memory control blocks     25        Seek error
               destroyed
       8        Insufficient memory       26        Unknown media type
       9        Invalid memory block      27        Sector not found
               address
      10        Invalid environment       28        Printer out of paper
      11        Invalid format            29        Write fault
      12        Invalid access code       30        Read fault
      13        Invalid data              31        General failure
      14        Reserved                  32        Sharing violation
      15        Invalid drive was         33        Lock violation
               specified
      16        Attempt to remove the     34        Invalid disk change
               current directory
      17        Not same device           35        FCB unavailable
      18        No more files             36        Sharing buffer overflow
      37-49     Reserved                  66        Network device type incorrect
      50        Network request not       67        Network name not found
               supported
      51        Remote computer not       68        Network name limit exceeded
               listening
      52        Duplicate name on         69        Network BIOS session limit
               network                            exceeded
      53        Network name not found    70        Temporarily paused
      54        Network busy              71        Network request not accepted
      55        Network device no longer 72        Print or disk redirection
               exists                             paused
      56        Network BIOS command      73-79     Reserved
               limit exceeded
      57        Network adapter hardware 80        File already exists
               error
      58        Incorrect response from  81        Reserved
               network
      59        Unexpected network error 82        Cannot make directory entry
      60        Incompatible remote       83        Fail on INT 24H
               adapter
      61        Print queue full          84        Too many redirections
      62        Not enough space for      85        Duplicate redirection
               print file
      63        Print file deleted        86        Invalid password
               (not enough space)
      64        Network name deleted      87        Invalid parameter
      65        Access denied             88        Network device fault

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Thank you!

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
You are right, I'm not getting a DOS error "unable to open file". I remember being very frustrated some years ago when I didn't have SET CLIPPER=F high enough and couldn't open a file though I could see that the file was right there!
I have rewritten the program using a modification of the net_use function. Thanks for the suggestion and the code. Finally got all my USE commands rewritten last night. Now I wait and see if that traps all of the delayed openings. I'm still a little nervous about the NTX files being delayed in opening and causing a crash, but I get the sense from you all that it won't be an issue. Time will tell. I'll be back looking for suggestions it that comes up.
Thank you all for the help.
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top