I am using the following code to make a connection to a SQL database. The code works fine on 98% of the PCs that I've run it on. The problem is, on a couple of PCs, the DB connection is never made. I know this because I can query for something that I know exists and an empty recordset is returned.

How can I check to see if the DB connection fails. It currently does not return any errors and doesn't affect the rest of the script, it just doesn't make the connection.

  $DSN="DRIVER=SQL Server;SERVER=myserver;UID=me;PWD=mypwd;DATABASE=mydb"
$Connection = CreateObject("ADODB.Connection")
$Command = CreateObject("ADODB.Command")
$Recordset = CreateObject("ADODB.Recordset")

$Connection.ConnectionString = $DSN
$Command.ActiveConnection = $Connection
$Recordset.CursorType = 3
$Recordset.LockType = 3
$Recordset.ActiveCommand = $Command

$Command.CommandText = "SELECT name FROM tbl_things where animal = 'dog'"
If $Recordset.RecordCount >= 1
If $Recordset.Fields("animal").Value > ""
$rc = "found an name"
$rc = "no name found"
$rc = "no records found" ;empty recordset
$Connection = 0
$Recordset = 0
$Command = 0