Answers.Body: <p>Answer:</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-16T18:27:52.397Z
Answers.LastActivityDate: 2021-04-16T18:27:52.397Z
Answers.UserDisplayName: Akuden 
Body: <p>Error: Craft CMS can’t connect to the database with the credentials in config/db.php.</p>
  <p>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:</p>
  <pre><code>        {% set myquery = craft.query()
          .select(['*'])
          .from(fromSql)
          .orderBy('Project ASC')
          .all(craft.app.theMSSQLConn)
          %}
  </code></pre>
  <p>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 &quot;Craft CMS requires the PDO_PGSQL driver to operate&quot;. 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.</p>
  <p>For more context, I was following an article by Andrew Welch here: <a href="https://nystudio107.com/blog/cutting-the-cord-removing-plugins#plugin-4-connect" rel="nofollow noreferrer">https://nystudio107.com/blog/cutting-the-cord-removing-plugins#plugin-4-connect</a></p>
  
Tags: <database>
Title: Cannot connect to outside mssql database in production
ThreadText: # Cannot connect to outside mssql database in production
  
  (Asked by: username_0 on 2021-01-11)
  
  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()
          .select(['*'])
          .from(fromSql)
          .orderBy('Project ASC')
          .all(craft.app.theMSSQLConn)
          %}
  
  ```
  
  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>
  
  **Tags:** database
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-04-16. Score: 1 | Accepted answer
  
  Answer:
  
  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.
  
  
  ---
  
  