The simplest testing code:
$objErr = ObjEvent("AutoIt.Error","MyErrFunc")
$sServer = 'server1'
$sDatabase = 'master'
$sUID = 'admin'
$sPWD = 'pwd'
$DSN = 'DRIVER={SQL Server};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUID &';PWD=' & $sPWD & ';'
$oConn = ObjCreate ("ADODB.Connection")
$oConn.ConnectionTimeout = 3 ; default is 15 s (must be supported by data provider DSN)
$oConn.Open($DSN)
If @error Then Exit
$oConn.Close
MsgBox(64, 'OK', 'Finished')
Func MyErrFunc()
MsgBox(48, 'COM Error', $objErr.description)
SetError(1)
EndFunc