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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alias is not Found

Status
Not open for further replies.

URStorres

Systems Engineer
Sep 17, 2018
1
MX
Regards.
I'm having an issue with a small code working with ODBC connection.

I'm using SQLEXCEC to select information form a table to a cursor, but once I need to use the cursor it can't be found.

This is part of the code:

**USE C:\PagosUniRed_SQL\TAbonos1.dbf ALIAS TAbonos1 IN SELECT(0) SHARED
GO TOP IN TAbonos1
DO WHILE !EOF("TAbonos1")
* Selecciona los datos del abono/ Select payment data
SQLEXEC(lc_con,"SELECT * FROM dbo.admDocumentos WHERE CIDDOCUMENTO = TAbonos1.CIDDOCUMENTOABONO and CIDDOCUMENTODE in(7,9,10,12)","TDoctos1")

* Seleccion los datos del cargo/ Select invoice data
SQLEXEC(lc_con,"SELECT * FROM dbo.admDocumentos WHERE CIDDOCUMENTO = TAbonos1.CIDDOCUMENTOCARGO and CIDDOCUMENTODE =4","TDoctos2")

* Inserta los datos al cursor TRelacion / Inserts the data to cursor TRelacion
lCantPagos = RECCOUNT("TDoctos1")
lCantFacturas= RECCOUNT("TDoctos2")
IF (lCantPagos > 0) THEN
IF (lCantFacturas>0) THEN

INSERT INTO TRelacion (pdocumde, pfolio, pserie, pfecha, pabonado, pmoneda, ptc,ffolio, fserie, ftotal, frefe ) VALUES (TDoctos1.CIDDOCUMENTODE, TDoctos1.CFOLIO, TDoctos1.CSERIEDOCUMENTO, TDoctos1.CFECHA, TAbonos1.CIMPORTEABONO, TDoctos1.CIDMONEDA, TDoctos1.CTIPOCAMBIO, TDoctos2.CFOLIO, TDoctos2.CSERIEDOCUMENTO, TDoctos2.CTOTAL, TDoctos2.CREFERENCIA)
ENDIF
ENDIF
SKIP IN TAbonos1
ENDDO
SQLDISCONNECT(lc_con)


As you can see, I'm selecting some fields from a previous cursor named TAbonos, and in each selection I created a cursor, TDoctos1 and TDoctos2.
The error comes out when I try to reccount TDoctos1 in variable lCantPagos.

May be I'm doing something wrong.

I attach the full code and a couple of images of the error and trace.
 
FYI: SQLExec can cause server side sql errors, which don't trigger VFP side errors, you have to look at the return value of SQLEXEC and other SQL passthrough functions. If this is -1, it indicates error informaiton is waiting for you and you can pull that via AERROR().

In short, apply sql passthrough error handling, which in works along this pattern:

Code:
lnResult = sqlpassthroughfunction()
If lnResult<0
   AERROR(laError)
   * look at what the array contains, in the simplest case in the Locals window of the debuger:
   SUSPEND
Endif

sqlpassthroughfunctions are all functions starting with SQL...(), eg this also applies to SQLCONNECT(), SQLSTRINGCONNECT(), SQLEXEC(), SQLPREPARE, etc. etc. Just read the help a bit.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top