GLOBAL issue: cannot find DB connection v3.5 - unable to access site with remote db

======== TEMPLATE BUG FORM ========

Wappler Version : 3.5
Operating System : mac
project: nodejs, mysql8, docker. local is docker db, stage and prod is aws rds db.

Expected behavior

What do you think should happen?

I should be able to normally operate my app on staging (haven’t pushed to prod). I should be able to login, view pages etc.

Note I can operate the site in my local environment - just not on AWS.

Actual behavior

I get this error: @patrick

{"status":"500","message":"Couldn't find database connection \"db\".","stack":"Error: Couldn't find database connection \"db\".\n at App.getDbConnection (/opt/node_app/lib/core/app.js:226:15)\n at new DatabaseProvider (/opt/node_app/lib/auth/database.js:9:23)\n at App.setAuthProvider (/opt/node_app/lib/core/app.js:132:26)\n at App.getAuthProvider (/opt/node_app/lib/core/app.js:149:31)\n at App.restrict (/opt/node_app/lib/modules/auth.js:42:37)\n at App._exec (/opt/node_app/lib/core/app.js:393:57)\n at App.exec (/opt/node_app/lib/core/app.js:335:20)\n at App.exec (/opt/node_app/lib/core/app.js:328:28)\n at /opt/node_app/lib/core/middleware.js:52:44\n at Layer.handle [as handle_request] (/opt/node_app/node_modules/express/lib/router/layer.js:95:5)"}

Is your database connection file still there? Check in app/modules/connections/db.json

Yep, still there. I’m able to access the DB locally when rending the site. On staging I’m also able to access the DB fine from within the DB Manager - but when I deploy and try to access the site on the server I get this error.

is it also available on your server?

Also are you using the new way with global db connections - or the old one, having them as step? (with experimental features off)

Yep also on server, and i’m using the new way with global db connections.

Same error for me on staging server.

Docker node, standalone db.
New way with global connections

Wappler connects fine, site gets error

1 Like

could you post the code from db.json - after stripping all sensitive info of course

{
  "name": "db",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "type": "mysql",
    "connection": {
      "host": "...",
      "port": "9906",
      "user": "...",
      "password": "...",
      "database": "..."
    }
  }
}

I believe the folder name connections should be Connections with a capital C.

what do you mean, sorry Patrick?

In my first image the folder name is all lowercase. Should I change the schema?

app/modules/connections/db.json

{
  "name": "db",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "client": "mysql",
    "connection": {
      "host": "mariadb.....com",
      "port": 32768,
      "user": "....",
      "password": ".......",
      "database": "....."
    }
  },
  "fileName": "db.json"
}

.wappler/targets/…/app/modules/connections/db.json

{
  "name": "db",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "client": "mysql",
    "connection": {
      "host": "mariadb.......com",
      "port": 32768,
      "user": "....",
      "password": ".....",
      "database": "....."
    }
  },
  "fileName": "db.json"
}

.wappler/targets/…/databases/db.json

{
"type": "mysql",
  "connection": {
    "host": "mariadb.......com",
    "port": 32768,
    "user": "....",
    "password": ".....",
    "database": "....."
  },
  "direct": true
}

@patrick - I tried changing the connections to Connections in the schema, and also the actual folder name to Connections, I redeployed and now get this error:

{"status":"500","message":"knex: Required configuration option 'client' is missing.","stack":"Error: knex: Required configuration option 'client' is missing.\n at new Client (/opt/node_app/node_modules/knex/lib/client.js:54:11)\n at Knex (/opt/node_app/node_modules/knex/lib/knex.js:53:28)\n at App.setDbConnection (/opt/node_app/lib/core/app.js:206:25)\n at App.getDbConnection (/opt/node_app/lib/core/app.js:223:25)\n at new DatabaseProvider (/opt/node_app/lib/auth/database.js:9:23)\n at App.setAuthProvider (/opt/node_app/lib/core/app.js:132:26)\n at App.getAuthProvider (/opt/node_app/lib/core/app.js:149:31)\n at App.restrict (/opt/node_app/lib/modules/auth.js:42:37)\n at App._exec (/opt/node_app/lib/core/app.js:393:57)\n at App.exec (/opt/node_app/lib/core/app.js:335:20)"}

Noting I also tried just changing the folder name, and leaving the schema. Same issue and error.

Removed capitalization in app.js lines 254 and 255.
Works now, but not sure if this is a proper fix :slight_smile:

    if (fs.existsSync(`app/modules/connections/${name}.json`)) {
      let action = fs.readJSONSync(`app/modules/connections/${name}.json`);
      return this.setDbConnection(name, action.options);
    }

In NodeJS @patrick connection folder should be all lowercase

1 Like

This didn’t fix it for me unfortunately.

Still now getting this error:

{“status”:“500”,“message”:“knex: Required configuration option ‘client’ is missing.”,“stack”:“Error: knex: Required configuration option ‘client’ is missing.\n at new Client (/opt/node_app/node_modules/knex/lib/client.js:54:11)\n at Knex (/opt/node_app/node_modules/knex/lib/knex.js:53:28)\n at App.setDbConnection (/opt/node_app/lib/core/app.js:206:25)\n at App.getDbConnection (/opt/node_app/lib/core/app.js:223:25)\n at new DatabaseProvider (/opt/node_app/lib/auth/database.js:9:23)\n at App.setAuthProvider (/opt/node_app/lib/core/app.js:132:26)\n at App.getAuthProvider (/opt/node_app/lib/core/app.js:149:31)\n at App.restrict (/opt/node_app/lib/modules/auth.js:42:37)\n at App._exec (/opt/node_app/lib/core/app.js:393:57)\n at App.exec (/opt/node_app/lib/core/app.js:335:20)”}

Then it is my mistake, in all other server models the connections folder was with a capital C.

Here an update that should load the database connection correctly, unzip it in lib/core.

app.zip (3.4 KB)

1 Like

@patrick

Tried the new file, still getting this error:

{“status”:“500”,“message”:“knex: Required configuration option ‘client’ is missing.”,“stack”:“Error: knex: Required configuration option ‘client’ is missing.\n at new Client (/opt/node_app/node_modules/knex/lib/client.js:54:11)\n at Knex (/opt/node_app/node_modules/knex/lib/knex.js:53:28)\n at App.setDbConnection (/opt/node_app/lib/core/app.js:206:25)\n at App.getDbConnection (/opt/node_app/lib/core/app.js:223:25)\n at new DatabaseProvider (/opt/node_app/lib/auth/database.js:9:23)\n at App.setAuthProvider (/opt/node_app/lib/core/app.js:132:26)\n at App.getAuthProvider (/opt/node_app/lib/core/app.js:149:31)\n at App.restrict (/opt/node_app/lib/modules/auth.js:42:37)\n at App._exec (/opt/node_app/lib/core/app.js:393:57)\n at App.exec (/opt/node_app/lib/core/app.js:335:20)”}

@mgaussie

Not sure why there is "type": "mysql" in your db.json, but it should be "client": "mysql",

2 Likes

That fixed it! Thank you as always.