Use AERROR() in Place of DBERROR() for ODBC Errors

Last reviewed: April 30, 1996
Article ID: Q130506
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

DBERROR() is no longer used to retrieve errors generated by an ODBC function.

AERROR() is a general Visual FoxPro error function that creates a memory variable array containing information about the most recent Visual FoxPro, OLE, or ODBC error.

MORE INFORMATION

The following example shows how to use AERROR(). Here a database is specified in the ODBC function SQLEXEC() that does not exist on the server.

   nHandle=SQLCONNECT('<SQL Server data source>','sa','')
   nSuccess=SQLEXEC(nHandle,'use bad_db')
   Dimension aErrArray[1]
   nNumerrors=AERROR(aErrArray)

The variable nNumerrors now contains the number of rows in the array aErrArray (2 in this case) and the array aErrArray contains the error information, as shown below:

AERRARRAY   Pub  A
(1,1)            N    1526    (           1526.00000000)
(1,2)            C    "Connectivity error: [Microsoft][ODBC SQL Server
                           Driver][SQL Server] Attempt to locate entry in
                           Sysdatabases for database 'bad_db' by name
                           failed - no entry found under that name. Make
                           sure that name is entered properly."
(1,3)            C    "[Microsoft][ODBC SQL Server Driver][SQL Server]
                           Attempt to locate entry in Sysdatabases for
                           database 'bad_db' by name failed - no entry
                           found under that name. Make sure that name is
                           entered properly."
(1,4)            C    "08004"
(1,5)            N    911      (            911.00000000)
(1,6)            N    1        (              1.00000000)
(1,7)            C    .NULL.
(2,1)            N    1526     (           1526.00000000)
(2,2)            C    "Connectivity error: [Microsoft][ODBC SQL Server
                           Driver][SQL Server] Attempt to locate entry in
                           Sysdatabases for database 'bad_db' by name
                           failed - no entry found under that name. Make
                           sure that name is entered properly."
(2,3)            C    "[Microsoft][ODBC SQL Server Driver][SQL Server]
                           Changed database context to 'pubs'."
(2,4)            C    "01000"
(2,5)            N    5701     (           5701.00000000)
(2,6)            N    1        (              1.00000000)
(2,7)            C    .NULL.

The following table describes the contents of each element when an ODBC error numbered 1526 occurs. The array contains two or more rows; one row for each ODBC error.

Element number Description

     1          Numeric. Contains 1526.
     2          Character. The text of the error message.
     3          Character. The text of the ODBC error message.
     4          Character. The current ODBC SQL state.
     5          Numeric. The error number from the ODBC data source.
     6          Numeric. The ODBC connection handle.
     7          The null value.


Additional reference words: 3.00 kbfest VFoxWin
KBCategory: kbprg
KBSubcategory: FxprgClientsvr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.