We are having an issue with a new application.
It is using 2 FoxPro databases, which both contain a stored procedure
called NewID(), and a table called ID_MASTER where the unique ID's are
located at.

We use the NewID() stored procedure as the default value for our
primary keys, called as NewID('TableName').
But at other times, we need to find out what the ID is before our
insert into the database, to link this ID in child tables for their
inserts.
Pretty straight forward so far.

The problem is that sometimes the newid() stored procedure seems to be
getting called from the wrong database, and it returns the wrong value.
This occurs in both instances above.

An example is:
INSERT INTO MARKIII!demand_order (bin_id, dmd_time_low, dmd_ready,
ord_id) ;
VALUES (laAvailableBins(iCount,1), lnEmptyTime, lbReady, .NULL.)

the primary key is dmd_id, and it has a default value of
NewID('demand_order'),yet sometimes it access the wrong database.

We have listed prior to this code SET DATABASE TO MARKIII, as well as
SET DATABASE TO (this.database_location)
this.database_location is the full path and database name to our
location.

Any help would be greatly appreciated.

Re: stored procedure called from wrong database by Olaf

Olaf
Sat Apr 01 05:54:41 CST 2006

> the primary key is dmd_id, and it has a default value of
> NewID('demand_order'),yet sometimes it access the wrong database.
>
> We have listed prior to this code SET DATABASE TO MARKIII, as well as
> SET DATABASE TO (this.database_location)
> this.database_location is the full path and database name to our
> location.

I did experience the same problem but could reliably solve it
by SET DATABASE TO the correct database before
inserting or appending records.

If you still have problems, then I'd suggest calling the procedures
differently in both databases, eg MARKIII_NewID() and
MyOtherDBC_NewID().

Perhaps it's even not, that the procedure of the wrong database
is executed, but the wrong ID_MASTER table is opened or was
already open. If you want to make sure, modify the NewID
procedure to close any table with that alias and then open the
correct table.

Bye, Olaf.