Error: Craft CMS can’t connect to the database with the credentials in config/db.php.

I have two database connections. One to mysql for the bulk of the website including all things craft, and one connection to mssql. I modified /config/app.php to include the mssql connection credentials to access them via twig:

        {% set myquery = craft.query()
        .orderBy('Project ASC')

This works on my local and staging environment, but the errors start on production. The file throwing the errors (mysite/vendor/craftcms/cms/src/db/Connection.php) first threw an error "Craft CMS requires the PDO_PGSQL driver to operate". I'm not using pgsql, but I installed the extension anyways and now I have a new error, in the same function of open(), stating craft cannot connect to the database with the credentials in config/db.php. The file config/db.php contains the mysql credentials which are correct and are working. I'm not sure what to do. It seems like Craft is attempting to open my mssql connection using the credentials in config/db.php as opposed to the credentials provided in config/app.php. Edit: craft.app.theMSSQLConn is returning the correct connection string.

For more context, I was following an article by Andrew Welch here: https://nystudio107.com/blog/cutting-the-cord-removing-plugins#plugin-4-connect

1 Answer 1



The server I was trying to connect to didn't have a CNAME set up in my corporate dns. So when I would switch environments some environments could see the server and others could not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.