Skip to content

Latest commit

 

History

History
79 lines (69 loc) · 3.32 KB

File metadata and controls

79 lines (69 loc) · 3.32 KB
title Error Object Properties Example (VB) | Microsoft Docs
ms.prod sql
ms.prod_service connectivity
ms.technology connectivity
ms.custom
ms.date 01/19/2017
ms.reviewer
ms.topic conceptual
dev_langs
VB
helpviewer_keywords
Number property [ADO], Visual Basic example
Source property [ADO], Visual Basic example
NativeError property [ADO], Visual Basic example
Description property [ADO], Visual Basic example
HelpFile property [ADO], Visual Basic example
SQLState property [ADO], Visual Basic example
HelpContext property [ADO], Visual Basic example
ms.assetid 5c728458-d85c-497c-afcf-2cfa36c3342a
author MightyPen
ms.author genemi

Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState Properties Example (VB)

This example triggers an error, traps it, and displays the Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState properties of the resulting Error object.

'BeginDescriptionVB  
Public Sub Main()  
  
    Dim Cnxn As ADODB.Connection  
    Dim Err As ADODB.Error  
    Dim strError As String  
  
    On Error GoTo ErrorHandler  
  
    ' Intentionally trigger an error  
    Set Cnxn = New ADODB.Connection  
    Cnxn.Open "nothing"  
  
    Set Cnxn = Nothing  
    Exit Sub  
  
ErrorHandler:  
  
    ' Enumerate Errors collection and display  
    ' properties of each Error object  
    For Each Err In Cnxn.Errors  
        strError = "Error #" & Err.Number & vbCr & _  
            "   " & Err.Description & vbCr & _  
            "   (Source: " & Err.Source & ")" & vbCr & _  
            "   (SQL State: " & Err.SQLState & ")" & vbCr & _  
            "   (NativeError: " & Err.NativeError & ")" & vbCr  
        If Err.HelpFile = "" Then  
            strError = strError & "   No Help file available"  
        Else  
            strError = strError & _  
               "   (HelpFile: " & Err.HelpFile & ")" & vbCr & _  
               "   (HelpContext: " & Err.HelpContext & ")" & _  
               vbCr & vbCr  
        End If  
  
        Debug.Print strError  
    Next  
  
    Resume Next  
End Sub  
'EndDescriptionVB  

See Also

Description Property
Error Object
HelpContext, HelpFile Properties
HelpContext, HelpFile Properties
NativeError Property (ADO)
Number Property (ADO)
Source Property (ADO Error)
SQLState Property