An error occurred using the connection to database '' on server 'server-name'

More than anything I hate it when an error message sends you on a wild goose chase.  Take the error message of: 

An error occurred using the connection to database '' on server 'server-name'

I recently did a deployment to AWS and I kept getting this error message.  I had the same connection string format on a local docker container and it worked fine but once I deployed it, nothing worked.  I ended up writing out the connection string into the logs, which I know isn't very secure but it was the only way to get to the bottom of it.

The database name was in the connection string but it turned out to be the user parameter, instead of username I should have been using uid (this is for a MySQL database connection).  I'm still not 100% sure why this works locally with a docker MySQL but not in AWS RDS.  The database driver should be the one taking care of the connection parsing and since it's the exact same code, which is deployed in a docker image, it should work the same.  One of these days, I'll spend a little more time digging into and if I figure it out I'll update this post. 

If anyone else knows the reason behind it, feel free to leave a comment.

Local Docker Used:

server=127.0.0.1;port=3306;database=my_database;username=my_user;password=my_secret_password

To get it to work in RDS is was:

server='my-db-address.rds.amazonaws.com';port=3306;database=my_database;uid=my_user;password=my_secret_password

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

JP
JP - Friday, 19 March 2021

In my case I had this message "An error occurred using the connection to database '' on server ''." and I just had to add the port number of my database.