When it comes to local testing and deploying on the live site most hosts will not allow remote connections to the db. So if you have the remote connection info specified in the file and try to test locally you will probably get an error like this.
When you go to the live server you will need to update the details in the connection file so that they work with your live db. You should be able to login to your hosting account to get the live details for the db connection.
Whenever you get a connection error like this it means just what it says, in this case it cannot make a connection to the server.