Connection refused when using Server Connect (even though main DB connection is ok)

I have a local setup using PHP for the backend, running on Docker and connecting to a MySQL database in another docker container.

I have added a database connection which I know has the correct credentials since it returns the DB tables without a problem.

I have added a server action to select from one of my tables. When I execute the query it returns all the records, also without a problem.

I have added a Server Connect which attempts to utilise the above server action but when I attach a table or repeater to this I get “SQLSTATE[HY000] [2002] Connection refused”.

Any clues?

Hi LemonPie,

Without presenting the structure of your setup (e.g.: Docker container names, screenshots of the DB configuration on Wappler and relevant Server Action steps), it’s difficult for someone to provide you meaningful help. Would you be able to show more information?

For instance, the last 2 paragraphs seem contradicting, hence we need to see your Wappler steps to ensure you’re attempting to connect to the same DB, since initially you said it worked but once you added a repeater it went haywire, which doesn’t make much sense as adding a repeater shouldn’t cause such a failure behaviour

Ok here are some more details:

  1. This screenshot show my database connection with tables:
    Screenshot 2023-04-13 at 19.32.11

  2. This screenshot shows a successful query result from my database query:

  3. This screenshot shows my Server Connect that utilises the above server action:

  4. This screenshot shows a table that uses the above Server Connect:
    Screenshot 2023-04-13 at 19.42.01

  5. This screenshot shows the result in my browser:

When I switch on debug I see that the 500 error is caused by “SQLSTATE[HY000] [2002] Connection refused”. This seems odd to me since I can connect to the database through (1) and (2) above.

I’m not saying it went haywire after adding a repeater. I’m saying that the database connection seems to be okay in Wappler but I’m getting a connection refused error in my browser.

Here’s some info that might help you…apologies if you already understand all this!

The database connection settings are per target. So if you can connect via one target, but not another, have a look at the connection in globals, paying close attention to the Active target selected in the editor.

There are two connection types. 1. is for the editor itself to connect, so it is from the perspective of the computer you are working on. 2. is for the server connect itself which is from the perspective of the server you are running on…again per target.

The repeater itself is not involved here, so you are correct that it is not the cause here.

1 Like

To complement the post above, you’ve configured Wappler’s Database Manager correctly, but here are the settings you need to edit for the server configuration:

So, you always need to edit DB credentials in 2 places (Wappler Database Manager and in the Workflows tab [Globals])

1 Like

Aha! That explains it!

This is the DB connection under Globals:

It’s a little different from the one that works in the DB Manager (different MySQL version):
Screenshot 2023-04-13 at 21.29.17

I still can’t connect through the DB connection under Globals.

Could the cause of my problem be that MySQL 8 isn’t offered as an option here?
Screenshot 2023-04-13 at 22.53.56

It is available in the DB Manager.

Show the server address, you can’t use 127.0.0.1 inside a (NodeJS?) Docker container to connect to a different (MySQL) container. If you search the forum you might find one of my replies somewhere about this issue

If using docker, try changing to port 9906

Okay I finally solved this. Since I’m using a Mac I’m able to use a built-in alias, namely docker.for.mac.localhost to allow me to connect to a database in another Docker container.

That wasn’t enough though. It seems that Wappler isn’t fully compatible with MySQL 8. This may be because password encryption changed in this version. So I switched to PostgreSQL and I’m back in business.

My global database connection looks like this:
Screenshot 2023-04-16 at 19.45.38

I hope this helps others facing the same issue.