ADODB LDAP Catch OLEException

Here is the code I took from Xojo forum to verify if a user and password works on a LDAP server:

Dim strUser, strPassword, strServer, strQuery As String

strUser = “ml6g\utiltest”
strPassword = “$wrongpassword$” // a wrong password
dim LogonServer as string
LogonServer = “my server”

Dim adoConnection, adoCommand,adoRecordset As OleObject

strQuery = “SELECT cn FROM 'LDAP://” + LogonServer + "’ WHERE ObjectClass=’*’ "

adoConnection = new OLEOBJECT(“ADODB.Connection”)
adoConnection.Provider = “ADsDSOOBJECT”
adoConnection.Properties(“User ID”) = strUser
adoConnection.Properties(“Password”) = strPassword
adoConnection.Properties(“Encrypt Password”) = false
adoConnection.open (“DS Query”, strUser, strPassword)

adoCommand = New OleObject(“ADODB.Command”)
adoCommand.ActiveConnection = adoConnection
adoCommand.CommandText = strQuery
adoCommand.Properties(“Size Limit”) = 1
adoRecordset = New OLEObject(“ADODB.Recordset”)

try
adoRecordset = adoCommand.Execute()
Catch ExecuteError As OLEException
// User did not manage to login
msgbox ExecuteError.message
adoConnection.close

adoConnection = Nil
adoCommand = Nil
adoRecordset = Nil
exit

End Try

The instruction
adoRecordset = adoCommand.Execute()
crashes in debug mode.

The Catch subroutine is not run. So, I am wondering if I missed something.

Thanks.

I don’t think that you missed something, I experienced the same issue with my project.

I’ve finally found an answer.

I have read again in Xojo feedback Case 29708 - Try Catch does not catch unsupported format exception.

There was a comment somewhere:
Please check that the Project menu, ‘Break On Exceptions’ item is unchecked.

I did it and it worked.
Hope it will help somebody else.