ADO - Description property
In ADO (ActiveX Data Objects), the Description property provides a text explanation of an error that occurred during a database operation.
It’s one of the key properties of the Error object (which belongs to the Errors collection of a Connection object).
Purpose
The Description property returns a human-readable message that describes the nature of the error — similar to what you’d see in a pop-up error box or debugger output.
Applies To
-
Errorobject (in theErrorscollection)
Syntax
error.Description
Read-only property.
Example
Dim conn As ADODB.Connection
Dim errObj As ADODB.Error
On Error Resume Next
' Try to open a connection with wrong credentials
Set conn = New ADODB.Connection
conn.Open "Provider=SQLOLEDB;Data Source=.;Initial Catalog=TestDB;User ID=wrong;Password=wrong"
' Check for errors
If conn.Errors.Count > 0 Then
For Each errObj In conn.Errors
Debug.Print "Error Number: " & errObj.Number
Debug.Print "Description: " & errObj.Description
Debug.Print "Source: " & errObj.Source
Debug.Print "SQLState: " & errObj.SQLState
Debug.Print "NativeError: " & errObj.NativeError
Debug.Print "-----------------------------"
Next
End If
Example Output:
Error Number: -2147217843
Description: Login failed for user 'wrong'.
Source: Microsoft OLE DB Provider for SQL Server
SQLState: 42000
NativeError: 18456
Here, the Description property gives the actual text message — "Login failed for user 'wrong'."
Common Usage
The Description property is typically used for:
-
Displaying or logging user-friendly error messages.
-
Debugging ADO operations (like failed queries, missing tables, etc.).
-
Understanding the cause of database or provider errors.
Key Points
| Property | Description |
|---|---|
| Object | Belongs to the Error object in the Errors collection |
| Type | Read-only, String |
| Purpose | Provides a textual description of the error |
| Typical Use | Error handling and debugging |
Example in Error Handling
On Error GoTo HandleError
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM NonExistentTable", conn
Exit Sub
HandleError:
Dim errObj As ADODB.Error
For Each errObj In conn.Errors
MsgBox "Error: " & errObj.Description, vbCritical, "ADO Error"
Next
Message Box Output:
Error: Invalid object name 'NonExistentTable'.
In Short:
-
Property:
Description -
Object:
Error -
Type: Read-only string
-
Meaning: Provides the text message describing the cause of an error.