I have been trying to get a database connection up and working for the past few days. The test connection has always been succesful, but i couldn't get queries working.
Our password had underscores "_" in it. I found an old post that stated that the connection didn't work with special characters, so i tried to remove them. Queries immediately started working. I hope this is something you can fix in your script.