0

I have deployed an application to heroku: https://stark-citadel-91743.herokuapp.com/

The app initially loads properly until you click a button that requires the database. Then it crashes.

Everything works in local development environment. I believe I have properly set up all connection settings for production in heroku dashboard's config variables (database url, database name, username, password). But in production it doesn't work.

Two evidences that it's not set up right: 1) When I log into the ClearDB MySQL plugin (in my heroku dashboard) under 'current connections' it says, 'No connections are currently established to the database.' 2) When I use postman to hit a custom endpoint I made just for testing a request to the database, I get: "Error adding color: Error: connect ECONNREFUSED 127.0.0.1:3306" <-- that 127.0.0.1 seems enlightening. Why would a deployed db have a connection on that address?

Any clues? Thank you!

208_man
  • 1,440
  • 3
  • 28
  • 59

1 Answers1

0

If your database is also set up at keroku host:

check the db setting(username, pw, port,etc.)

If you actually need to connect back to your own database(which is hosted by you or other third party);

You should find out the setting and replace with 127.0.0.1:3306, which is only work for local env

Update:

127.0.0.1 is localhost, which is your machine. Your test case is working because your server and your database are hosting on the same machine(which both have same ip). However, when your code are deployed to heroku, your heroku server cannot find a database hosted on same machine. This is why your are having this problem

tung yu
  • 94
  • 4
  • Hello @tung yu. Thank you but I'm not totally clear what you are saying. I understand about username, pw, port, and have checked that already. What do you mean about connect back 'to your own database'? Can you elaborate? – 208_man Jun 12 '18 at 04:21
  • updated. In other words, first, you have to understand what if heroku want you to use your database or a database hosted by them – tung yu Jun 12 '18 at 04:32
  • Ah yes, I have heroku set to use database hosted by them. Using ClearDB plugin. But the application is not successfully connecting to this ClearDB database. I can't fig what I'm doing wrong. I've spent almost a day working on it. Thank you if you have any suggestions. I can share repo if you want to see code. – 208_man Jun 12 '18 at 05:50
  • in this case, please check [link](https://stackoverflow.com/questions/9822313/remote-connect-to-cleardb-heroku-database?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – tung yu Jun 12 '18 at 06:10
  • I am not a heroku user, so I guess there’s nothing more I can do than this – tung yu Jun 12 '18 at 06:13