Can you verify that the string your "executing" in your script is EXACTLY the same as the one your running manually ... have you tried dumping your string out to the console to make sure all the variables are being resolved correctly, like this:

?"conn=" + $SQLCon
?"sql=" + $SQLCode

$EXResult = DBExecuteSQL($SQLCon, $SQLCode,4)

are you missing something small, like forgetting to add a required semi-colon to the end of the statement ? something your doing interactively that you missed in your script ? grasping at straws here ;0)