Page 1 of 1
Strange message
Posted: Wed Oct 21, 2009 5:53 pm
by hag
I have a user who received the following error
Code: Select all | Expand
Application
===========
Path and name: E:\Spectral\Cash Flow\cashver3.exe (32 bits)
Size: ********* bytes
Time from start: 0 hours 1 mins 49 secs
Error occurred at: 10/21/09, 11:50:12
Error description: Error DBCMD/2001 Workarea not in use: ORDCREATE
Stack Calls
===========
Called from: => ORDCREATE(0)
Called from: source\rdd\rddord.prg => DBCREATEINDEX(59)
Called from: .\CASHVER3.PRG => GLOBAL1(2378)
Called from: .\CASHVER3.PRG => MSCREEN2(802)
The error occurs at this line
use (exptyd) alias expty new
index on expty->prod_num to expty
<<<<< hereHow is it posible the work area no in use when the above line opens it?
This happens once in a while.
Re: Strange message
Posted: Thu Oct 22, 2009 8:03 am
by hua
Harvey,
I believe the error message itself is self-explanatory. Your attempt to "use" a dbf obviously failed. It could be that the user runs more than 1 instance of your program or some other part of your program already has it opened or some other reasons.
That's why I normally open my dbf using a wrapper function that'll be able to let me know whether an attempt to open a dbf is successful or not. Here's a code snippet
Code: Select all | Expand
#include "fivewin.ch"
#define NET_WAIT .05
#define NET_SECS 5
function main()
set exclusive off
begin sequence
if net_use("customer", .f.)
set index to customer
else
break
endif
if net_use("invoice", .f.)
index on inv to invoice
else
break
endif
recover
dbCloseAll()
msgstop("Can't proceed. Some data file can't be opened. Aborting...")
return nil
end
// continue with the rest of the program
.
.
return nil
//-----------------------------------------------------------------------------------------
function Net_Use( cDatabase, lOpenMode, nSeconds, cAlias, lRandom )
LOCAL lForever // Retry forever?
LOCAL lReturn:= .f.
DEFAULT nSeconds := NET_SECS
default lRandom := .f.
lForever := ( nSeconds == 0 )
if lRandom // auto-generate a random alias for user
cAlias := tempfile() // generate a random alias
endif
/* Keep trying as long as our time''s not up */
while ( lForever .or. ( nSeconds > 0 ) )
IF lOpenMode
dbUseArea(.t.,, cDatabase, cAlias, .f. )
else
dbUseArea(.t.,, cDatabase, cAlias, .t. )
ENDIF
IF !neterr()
lReturn := .t.
exit
ELSE
IF !MsgYesNo( "Cannot open file '" + UPPER(cDatabase) + ".DBF'. Retry?" )
lReturn := .f.
Exit
ENDIF
ENDIF
inkey( NET_WAIT ) // Wait
nSeconds -= NET_WAIT
ENDDO
RETURN( lReturn )
Re: Strange message
Posted: Thu Oct 22, 2009 6:02 pm
by hag
Hua:
thank you for your response. I clearly understand the process and the code you sent me.
However I'm confused because if I attempted to open the database which is already open I would get an error message and it would not allow me to reopen the database.
So if it allows me to open the database here without an error message:
Use (expty) alias expty new
then why on the next line when I'm indexing the database would it tell me that database is not open.
There is no other copy of the program running and this is at the very beginning of the program so the database has not been opened and closed. It just happens for what appears to be no apparent reason.
Actually I've had several concerns because the following code has also told me the database is not open I'll show you lines 1 line blows out the other does not.
gl->(dbseek())
gl->ty1 := var
gl->(dbseek()) <<<< tells me work area NOT in use???????
Any thoughts?
Re: Strange message
Posted: Thu Oct 22, 2009 9:39 pm
by Jonathan Hodder
Hi Harvey,
Hua has the correct method updated for win.
This method goes way back to early clipper days.
The neterr() function is what u need to test for.
From Clipper manual
This example opens a shared database file with associated
index files in a network environment. If NETERR() returns false
(.F.), indicating the USE was successful, the indexes are opened:
USE Accounts SHARED NEW
IF !NETERR()
SET INDEX TO AcctNames, AcctZip
ELSE
? "File open failed"
BREAK
ENDIF
Put in neterr() after 'use' it will return a true or false.
Re: Strange message
Posted: Thu Oct 22, 2009 9:51 pm
by hag
Thanks for the response.
Are you saying that you can open a file get no error message but the file is not open so there needs to be a test to see if it opened correctly.
So in the example I gave on one line it was open but on the next line it wasn't How is that possible. In this example I'm not opening a database its already been opened yet its ok on one line of code then the next no good.
This was the example:
gl->(dbseek()) <<<<<< it works
gl->ty1 := var <<<<<< it works
gl->(dbseek()) <<<< tells me work area NOT in use???????
That seems odd to me.
When I was using old fw192 it never happened only after the conversion to fwh.
Very strange
Re: Strange message
Posted: Thu Oct 22, 2009 9:52 pm
by TecniSoftware
hag wrote:
The error occurs at this line
use (exptyd) alias expty new
index on expty->prod_num to expty [b]<<<<< here[/b]
How is it posible the work area no in use when the above line opens it?
This happens once in a while.
Don´t include the alias in the key expresion, just:
index on prod_num to expty
Regards
Re: Strange message
Posted: Fri Oct 23, 2009 1:39 am
by hua
Harvey,
hag wrote:Are you saying that you can open a file get no error message but the file is not open so there needs to be a test to see if it opened correctly.
That has happened to me before and the reason why I make it a point to never use USE on its own. I'm not really sure what's causing you to see the errors that you're getting but I very much doubt the cause is somewhere in the [x]Harbour's RDD itself. If that was the case, there'd reports from a lot of other programmers.
Unless you can come up with some self-contained example that demonstrates the error, I've no further idea on how to approach this, sorry

I do recommend for the time being you replace all standalone USE with net_use() first, give that to your customer and wait and see if the error recurs. For all we know, the error might be due to some sort of network lag but I'm just guessing here.
Re: Strange message
Posted: Fri Oct 23, 2009 5:06 am
by James Bott
Harvey,
use (exptyd) alias expty new
index on expty->prod_num to expty <<<<< here
How is it posible the work area no in use when the above line opens it?
Correction, the above line
attempts to open it. If it is unsuccessful in opening it, there will not be any error message. As others have mentioned, you have to check neterr() to find out if there was an error in attempting to open the file. Otherwise, you
will get an error message on the next line as you found out.
In this example I'm not opening a database its already been opened yet its ok on one line of code then the next no good.
This was the example:
gl->(dbseek()) <<<<<< it works
gl->ty1 := var <<<<<< it works
gl->(dbseek()) <<<< tells me work area NOT in use???????
I think you must be oversimplifiying your example. I have been programming in xBase since it was invented in the early 80's and I have never seen anything like your example.
So, you have to write your programs to handle the possiblity that the desired database won't be successfully opened.
Alternately, my TData class automatically handles file open errors and makes automatic retrys. This makes your work much easier.
Regards,
James
Re: Strange message
Posted: Fri Oct 23, 2009 3:25 pm
by hag
Ill be outof town for about 5 days and get back to the discussion at that time. Thanks all for the help.