Can't connect node to SQL Server - node.js

I'm trying to connect a node app with a SQL Server database, but I keep getting this error:
Error while connecting database: ConnectionError:
Error: [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid [87].
Error: [Microsoft][SQL Server Native Client 11.0]Login timeout expired
Error: [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
I use the node package mssql with driver msnodesqlv8, and this is my db config:
const dbConfig = {
user: "user",
password: "password",
driver: 'msnodesqlv8',
server: 'DESKTOP-QG3R51Q',
database: 'WeighingScales',
options: {
instanceName: 'SQLEXPRESS',
trustedConnection: true,
}
};

Related

Connect to LocalDB\MSSQLLocalDB with Objection.js Knexfile

I am trying to connect to a LocalDB\MSSQLLocalDB SQLExpress instance in my Node.js application that uses Objection.js/Knex for the data layer.
When I try to run a migration it fails to connect to the database. But I can connect via SSMS without issue.
Here is my Knexfile.js connection settings
module.exports = {
development: {
client: 'mssql',
useNullAsDefault: true,
connection: {
server: '(LocalDB)\\MSSQLLocalDB',
user: 'localadmin',
password: 'password$',
database: 'database'
},
migrations: {
directory: './migrations',
tableName: 'knex_migrations'
},
seeds: {
directory: './seeds'
},
...knexSnakeCaseMappers()
}
};
When I run a migration it gives the following error:
Failed to connect to (LocalDB)\MSSQLLocalDB:1433 - getaddrinfo ENOTFOUND (LocalDB)\MSSQLLocalDB
Error: Failed to connect to (LocalDB)\MSSQLLocalDB:1433 - getaddrinfo ENOTFOUND (LocalDB)\MSSQLLocalDB
at Connection.socketError (D:\Code\backend\node_modules\tedious\lib\connection.js:1393:28)
at D:\Code\backend\node_modules\tedious\lib\connection.js:1153:21
at GetAddrInfoReqWrap.callback (D:\Code\backend\node_modules\tedious\lib\connector.js:195:16)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:77:17)
I believe this is an issue with tcp/ip settings in SqlExpress but I cannot find an easy way to change those.
Is there any settings for the Knexfile that will allow for a SQLExpress database connection?
LocalDB only accepts named pipes connections. Use proper SQL Express and enable TCP connections

Unable to connect to CloudSql from my Kuberernetes Cluster through cloudsqlproxy sidecar

while trying to connect to my cloudsql instance I am getting this error
{
errorno: "ETIMEDOUT",
code: "ETIMEDOUT",
syscall: "connect",
fatal: true
}
this is the log from my cloudsqlproxy container
2020/06/09 15:53:04 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.
2020/06/09 15:53:04 using credential file for authentication; email=lion-db#estatelion-test-275318.iam.gserviceaccount.com
2020/06/09 15:53:04 Listening on 127.0.0.1:3306 for estatelion-test-275318:us-central1:estatelion
2020/06/09 15:53:04 Ready for new connections
but my nodejs application is unable to connect to it
const connection = mysql.createPool({
connectionLimit: 10,
host: config.get("database").host, // localhost
user: config.get("database").user, // cloud proxy user for my cloudsql instance
password: config.get("database").password, // password
database: config.get("database").db_name, // database
});
Well I found the solution to this
I just updated the Cluster version to 1.15.11-gke.15 from 1.14.* (I dont remember the rest ) and it worked fine.
I think there is some bug in the default GKE version of the deployment.
Thanks Everyone for your gracious time and effort. :-)

Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? When lifting sails

Hi guys im receiving an error
Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? Error details: { [MongoError: failed to connect to server on first connect] name: 'MongoError', message: 'failed to connect to server on first connect' }
I'm using a previous version of Sails since that its the version that they are currently using
Sails ~0.12.4
nodejs -v 4.2.6
npm -v 3.5.2
error: A hook (`orm`) failed to load!
error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?
Error details:{ [MongoError: failed to connect to server [192.168.2.45:27017] on first connect] name: 'MongoError',
failed to connect to server [192.168.2.45:27017] on first connect]
name: 'MongoError', message: 'failed to connect to server [192.168.2.45:27017] on first connect' }
My config/connection.js looks like this
module.exports.connections = {
localDiskDb: {
adapter: 'sails-disk'
},
mongodbServer: {
adapter: 'sails-mongo',
host: '192.168.2.45',
port: 27017,
user : 'dbAdmin',
password : 'hiveslab',
database: 'sauce_db'
},
};
I'm stuck on this for a day and I'm pretty much of a newbie here. Hopefully you guys can lead me to the right resolution. Thank you in advance have a good day.

getaddrinfo ENOTFOUND while connecting to SQL Server from Node.js

I am trying to connect to my SQL Server from Node.js and I am getting this exception:
ERROR: Failed to connect to WAMG9120116\SQLEXPRESS:1433 - getaddrinfo ENOTFOUND WAMG9120116\SQLEXPRESS.
Below is the configuration.
# DATABASE
DATABASE_NAME=AeroPresentationApi
DATABASE_HOST=WAMG9120116\SQLEXPRESS
DATABASE_PORT=1433
DATABASE_USERNAME=XXXX
DATABASE_PASSWORD=XXXXXX
RUN_MIGRATIONS_ON_STARTUP=true
We are connecting to DB via this:-
const sequelize = new Sequelize(
databaseConfig.database,
databaseConfig.username,
databaseConfig.password,
databaseConfig,
);
Can anyone tell me what is going on ?
NOTE: I was able to connect to SQL Server from SSMS using User Name and Password.

Azure + Cassandra certified by Bitnami VM + nodejs app: Cannot connect to cassandra from remote app

Using datastax nodejs driver: 'cassandra-driver'
Connecting to database in my nodejs app server backend as:
const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: [ '${azure_vm_ip}' ] });
Output log:
{ [Error: All host(s) tried for query failed. First host tried, azure_vm_ip:9042: Error: Connection timeout. See innerErrors.]
innerErrors:
{ 'azure_vm_ip:9042':
{ [Error: Connection timeout]
message: 'Connection timeout',
info: 'Cassandra Driver Error' } },
info: 'Represents an error when a query cannot be performed because no host is available or could be reached by the driver.',
message: 'All host(s) tried for query failed. First host tried, azure_vm_ip:9042: Error: Connection timeout. See innerErrors.' }
Questions:
Should I edit something on the default cassandra.yaml file? If
so, what?
Should I do something with firewall? If so, what?
Should I pass in more options in new cassandra.Client({
contactPoints: [ '${azure_vm_ip}' ] })? If so, What?
Make sure you have set rule for 9042 port in NSG. Also check whether the same port is in listening mode inside the VM.

Resources