Connecting to a different MySQL server through Sails JS - node.js

I have a use case where I need to fetch data from two different DBs placed on different server(one of them being my own localhost/dev/prod). On providing details for connection using adapter : 'sails-mysql', whenever i try & access the DB(for a simple select query), it throws this exception:
debug: err, response -- Error: Could not connect to MySQL:
Error: Handshake inactivity timeout
at afterwards (/Users/xx/code/xx/xx/node_modules/sails-mysql/lib/connections/spawn.js:72:13)
at /Users/xx/code/xx/xx/node_modules/sails-mysql/lib/connections/spawn.js:40:7
at Handshake.onConnect [as _callback] (/Users/xx/code/xx/xx/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:54:9)
at Handshake.Sequence.end (/Users/xx/code/xx/xx/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at /Users/xx/code/xx/xx/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:399:18
at Array.forEach (<anonymous>)
at /Users/xx/code/xx/xx/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:398:13
at process._tickCallback (internal/process/next_tick.js:112:11) undefined
Example of connections.js:
MySQLServerForDataServer: {
adapter: 'sails-mysql',
host: (process.env.DBNAME_DATA_SERVER_HOST),
user: (process.env.DBNAME_DATA_SERVER_USER),
password: (process.env.DBNAME_DATA_SERVER_PWD),
database: (process.env.DBNAME_DATA_SERVER_DB)
}
I'm able to access this server through Valentina Studio or whatever(ssh key is added on there server too), but through code, it's not letting me through.
Can anyone suggest something which might help me connect to this DB Server?

Related

ConnectionError: Login failed for user '' while window authentication using Nodejs(Nestjs), msnodesqlv8, typeORM

I have to connect with mssql database using window authentication where I am using Nodejs and msnodesqlv8. I followed How to connect to SQL Server with windows authentication from Node.JS using mssql module to do the setup code but as it's window authentication so no username/password required but after writing code
connection using above link
const sql = require("mssql/msnodesqlv8");
const conn = new sql.ConnectionPool({
database: "db_name",
server: "server_name",
driver: "msnodesqlv8",
options: {
trustedConnection: true
}
});
conn.connect().then(() => {
// ... sproc call, error catching, etc
// example: https://github.com/patriksimek/node-mssql#request
});
I am getting this error ConnectionError: Login failed for user '', I tried a lot of links to understand the root cause but I am unable to understand also I am working on Mac M1, Azure data studio where manually I am not able to connect to database using window authentication as I am getting error 'Connection failed due to Kerberos error' so is this the cause, please help me to understand the issue.

Could not connect to MongoDB! TypeError: OpenIDConnectStrategy requires an issuer option

This the replication of the same question Could not connect to MongoDb : openidconnect strategy requires an issuer option.
In local its working fine by using local MongoDB. Used Mongo URI for server setup, in server the following error received while start the meanJS project.
Could not connect to MongoDB!
TypeError: OpenIDConnectStrategy requires an issuer option
at Strategy (/project_dir/node_modules/passport-openidconnect/lib/strategy.js:31:32)
at new Strategy (/project_dir/node_modules/passport-paypal-openidconnect/lib/passport-paypal-openidconnect/strategy.js:60:25)
at module.exports (/project_dir/modules/users/server/config/strategies/paypal.js:11:16)
at /project_dir/modules/users/server/config/users.server.config.js:31:36
at Array.forEach (<anonymous>)
at module.exports (/project_dir/modules/users/server/config/users.server.config.js:30:78)
at /project_dir/config/lib/express.js:139:38
at Array.forEach (<anonymous>)
at Object.module.exports.initModulesConfiguration (/project_dir/config/lib/express.js:138:31)
at Object.module.exports.init (/project_dir/config/lib/express.js:250:8)
at /project_dir/config/lib/app.js:26:23
at /project_dir/config/lib/mongoose.js:35:21
at process._tickCallback (internal/process/next_tick.js:68:7)
There is no proper solution for this issue, kindly provide a way to get out of this issue. Thanks in advance

Issues accessing ClearDb MySql from Heroku hosted NodeJS/Express app

I'm in the process of getting my React/NodeJS/Express app with a MySql database up and running on Heroku (using free dynos).
I'm using ClearDb ("Punch" licensing level) to host my MySql database in production.
I am using the mysql2 npm package to connect to mysql using connection pools.
I've successfully deployed the app, and can get my login screen to show up in the Heroku staging environment.
When the app tries to run the first query that hits the database, after 10 seconds, I see this message in the logs:
2021-08-30T15:04:44.867293+00:00 app[web.1]: executing DB query
2021-08-30T15:04:54.877125+00:00 app[web.1]: Error: connect ETIMEDOUT
2021-08-30T15:04:54.877132+00:00 app[web.1]: at /app/server/common/db.js:27:19
2021-08-30T15:04:54.877133+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:95:5)
The query is very simple, and the database barely has any data in the database. The query is running against a table with less than 20 rows in it.
Here is what I've tried:
Connect my app running on my local machine to ClearDb's production instance. Works fine.
Connect to ClearDb's production instance via MySql Workbench. Works fine.
Built a simple health check endpoint that executes the query "select 1". I get the same error in the logs as above.
Here is how I'm connecting (I will be migrating to using SSL for the connection before going live with my app)
const mysql = require('mysql2/promise')
const config = {
host: process.env.DB_HOSTNAME,
port: process.env.DB_PORT,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
insecureAuth : true,
database: process.env.DB_NAME,
timezone:'+00:00'
};
const pool = mysql.createPool(config)

MongoDB connection error from NodeJS backend using mongoose

I have deployed a mongodb replicaset which I am trying to connect to using a node js backend application.
My connection code is as follows:
mongoose.connect(config.database, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
dbName:"db7_0",
user:'****',
pass:'****'
}).catch(function (err) {
console.log('The connection to the database could not be established. Error details: ', err);
});
'config.database' is the connection URL which I have put together using the mongodb documentation and is the following:
database: "mongodb://user:pw#xxx.eu-west-1.compute.amazonaws.com:27017,xxx.eu-west-1.compute.amazonaws.com:27017,xxx.eu-west-1.compute.amazonaws.com:27017/db7_0?replicaSet=rs0"
Note: 'user', 'pw' and 'xxx' are just placeholders for the real details which I have used in the connection string.
When I start up the server and the database connection is created, my logs show the following:
And my application is throwing the following MongoNetworkError:
The connection to the database could not be established. Error details: MongoTimeoutError: Server selection timed out after 30000 ms
at Timeout._onTimeout (C:\Dev\sc\node_modules\mongoose\node_modules\mongodb\lib\core\sdam\server_selection.js:308:9)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
name: 'MongoTimeoutError',
[Symbol(mongoErrorContextSymbol)]: {}
}
Database error MongoTimeoutError: Server selection timed out after 30000 ms
I've tried many different approaches to fixing the issue, such as specifying the user, password and database in the connection string as well as the mongoose.connect parameters and this did not make any difference. I was initially on Mongoose v5.9.2 (now v5.8.2) and the behaviour is still the same.
Also, please note that running the following in the command prompt does work:
mongo "mongodb://user:pw#xx.xx.xxx.xx:27017/db7_0"
So i suspect it might be a mongoose error however I am struggling to figure out the issue.
It turns out that my issue was caused by the configuration of the replicaSet.
I had configured each of the members of the replicaSet using the ipv6 address of each member, which was not allowing me to connect to the replica set for some reason. I then reconfigured the replica set and changed each host address to the public DNS ipv4 address of each member and it worked.

PostgreSQL not working with Node.js on Heroku

I'm trying to work on a node.js application using Heroku and a PostgreSQL database.
I have followed the tutorial on Heroku documentation:
https://devcenter.heroku.com/articles/nodejs#using-a-postgres-database
Dependencies are good, and my code is basically the following:
var pg = require('pg');
pg.connect(process.env.DATABASE_URL, function(err, client) {
var query = client.query('CREATE TABLE users (id bigint auto_increment not null, login varchar(250), constraint pk_users primary key (id) )');
query.on('row', function(row) {
console.log(JSON.stringify(row));
});
});
I have tried various forms of this query, like this one:
var client = new pg.Client(process.env.DATABASE_URL);
client.connect();
But I got each time this error in my heroku logs:
at Object.afterConnect [as oncomplete] (net.js:875:19)
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
If someone has already encountered this kind of problem, any help would be welcome.
Thank you.
I would suggest trying a console.log(process.env.DATABASE_URL); and then using that address to manually connect using a client on your local machine. I understand that the Heroku database servers are open for remote connection(but I have been wrong before).
Failing that you can get a heroku console and use the postgre client.
ECONNREFUSED is a socket error that pops up when you try to connect to an address that is not contactable/connectable/listening.
If process.env.DATABASE_URL does return the correct and connectible address then I would be doing console.log(pg); to ensure that object is what I would expect it to be.

Resources