SQLError (function)

Syntax

SQLError(ErrArray [, ID])

Description

Retrieves driver-specific error information for the most recent SQL functions that failed.

Comments

This function is called after any other SQL function fails. Error information is returned in a two-dimensional array (ErrArray). The following table describes the parameters to the SQLError function:

 

Parameter

Description

 

ErrArray

Two-dimensional Variant array, which can be dynamic or fixed.

If the array is fixed, it must be (x,3), where x is the number of errors you want returned. If x is too small to hold all the errors, then the extra error information is discarded. If x is greater than the number of errors available, all errors are returned, and the empty array elements are set to Empty.

If the array is dynamic, it will be resized to hold the exact number of errors.

 

ID

Optional Long parameter specifying a connection ID. If this parameter is omitted, error information is returned for the most recent SQL function call.

 

Each array entry in the ErrArray parameter describes one error. The three elements in each array entry contain the following information:

 

Element

Value

 

(entry,0)

The ODBC error state, indicated by a Long containing the error class and subclass.

 

(entry,1)

The ODBC native error code, indicated by a Long.

 

(entry,2)

The text error message returned by the driver. This field is String type.

 

For example, to retrieve the ODBC text error message of the first returned error, the array is referenced as:

  ErrArray(0,2)

The SQLError function returns the number of errors found.

The Basic Control Engine generates a runtime error if SQLError fails. (You cannot use the SQLError function to gather additional error information in this case.)

Example

This example forces a connection error and traps it for use with the SQLError function.

Sub Main()
  Dim a() As Variant
  On Error Goto Trap
  id& = SQLOpen("",,4)
  id& = SQLClose(id&)
  Exit Sub

Trap:
  rc% = SQLError(a)
  If (rc%) Then
  For x = 0 To (rc% - 1)
      MsgBox "The SQL state returned was: " & a(x,0)
      MsgBox "The native error code returned was: " & a(x,1)
      MsgBox a(x,2)
    Next x
  End If
End Sub

 

 

 

More information

S