Visual Basic with ADO - OLE DB Provider for Teradata

OLE DB Provider for Teradata User Guide

Product
OLE DB Provider for Teradata
Release Number
15.00
Language
English (United States)
Last Update
2018-09-28
dita:id
B035-2498
Product Category
Teradata Tools and Utilities

Visual Basic with ADO

Using ActiveX Data Objects (ADO), Teradata Database errors are mapped to the Custom Error Object. See “ADO Dynamic Properties” on page 119.

The mapping between a Custom Error Object and a Teradata Database error is as follows:

 

Table 23: Custom Error Object Mapping to Teradata Database Error

Error Properties

Teradata Database Error Objects

Description

Description of error returned from Teradata Database

NativeError

Native Error Code returned from Teradata Database.

Number

Enumerated type of ErrorValueEnum. For more information, refer to the MSDN Library search topic:

ErrorValueEnum enumerated constants

Source

Returns OLE DB Provider for Teradata.

SQLState

5-digit character code returned by OLE DB Provider for Teradata.

Example  

The following code checks for errors using Visual Basic and ADO.

Dim strTeraCnxn As String
Dim TeraCnxn As ADODB.Connection
Dim TeraObjCmd As New ADODB.Command
Dim TeraObjRs As ADODB.Recordset
 
‘Setting up the ERROR HANDLER
    
On Error GoTo ADOError
    
' Going to Open Connection
 
strTeraCnxn = "Provider=TDOLEDB;Data Source=Teradata1" & _
        "User Id=userid;Password=password;" & _
"Extended Properties=
””Session Mode=ANSI;Enable Parser=NO;DefaultDatabase=Project1;””;’
 
Set TeraCnxn = New ADODB.Connection
TeraCnxn.Open strTeraCnxn
 
TeraObjCmd.ActiveConnection = TeraCnxn
    
TeraObjCmd.CommandText = "SELECT f1, f2, f3 from table1"
TeraObjCmd.CommandType = adCmdText
   
Set TeraObjRs = TeraObjCmd.Execute
    
‘--------------------------------------------------------------
‘ Continue Processing Records returned from command object
‘--------------------------------------------------------------
' Going to clean up objects
 
TeraObjRs.Close
Set objCmd = Nothing
   
TeraCnxn.Close
Set TeraCnxn = Nothing
    
Exit Sub
    
‘ This is the ERROR HANDLER
 
ADOError:
Dim TeraObjError As ADODB.Error
Dim strError As String
If TeraCnxn.Errors.Count > 0 Then
For Each TeraObjError In TeraCnxn.Errors
   strError = strError & "Error #" & TeraObjError.Number & _
     " " & TeraObjError.Description & vbCrLf & _
      "NativeError: " & TeraObjError.NativeError & vbCrLf & _
     "SQLState: " & TeraObjError.SQLState & vbCrLf & _
     "Reported by: " & TeraObjError.Source                 								
      Next
      MsgBox strError
End If