As I am using SQL Server 18 and nodeJs version12, below code snippet I tried and I get an error shown below.
Code snippet:
var sql = require('mssql/msnodesqlv8');
var config = {
driver: 'msnodesqlv8',
connectionString: 'Driver=SQL Server Native Client 11.0;Server=Server_name;Database=DBname;Trusted_Connection=yes;'
};
sql.connect(config)
.then(function() {
console.log("done");
})
.catch(function(err) {
console.log(err);
});
Error :
ConnectionError: Error: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. ,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.
at C:\Users\user\test-app\node_modules\mssql\lib\msnodesqlv8\connection-pool.js:56:17
at Immediate. (C:\Users\user\test-app\node_modules\msnodesqlv8\lib\connection.js:362:15)
at processImmediate (internal/timers.js:456:21) {
code: undefined,
name: 'ConnectionError'
Related
I have a node js app. And I use Redis from Heroku Redis(with async-redis library).
Actually, I have two different Heroku accounts and two different Node.js apps hosted by Heroku. But except Redis credentials, both apps are the same code.
The interesting thing on my app I can connect to first Heroku Redis instance. But I can't connect to new Heroku Redis instance. Besides I deleted and created new instances, bu they don't work.
The error is:
Error: Redis connection to redis-123.compute.amazonaws.com:28680 failed - read ECONNRESET\n
at TCP.onStreamRead (internal/stream_base_commons.js:162:27)
My connection statement like this:
var redisPassword = 'password123';
var redisOptions = { host: 'redis-123.cloud.redislabs.com', port: '17371', auth_pass: redisPassword }
//var redisPassword = 'password123';
//var redisOptions = { host: 'redis-123.compute.amazonaws.com', port: '28680', auth_pass: redisPassword }
const client = redis.createClient(redisOptions);
client.on('connect', function () {
console.log('Redis client connected');
});
client.on('error', function (err) {
console.log('An error on Redis connection: ' + err);
});
As I can see there is the only thing that different on Heroku Redis instances. My first Redis instance hosts at cloud.redislabs.com but the second instance(that i can't connect) hosts at compute.amazonaws.com.
Any help will be much appreciated.
I encountered this situation and it turned out the with "Heroku Redis" connecting via TLS worked (the url that starts with rediss) once I adjusted my client code to connect following the example provided in the Heroku redis docs:
https://devcenter.heroku.com/articles/connecting-heroku-redis#ioredis-module
const Redis = require("ioredis");
const client = new Redis(process.env.REDIS_URL, {
tls: {
rejectUnauthorized: false
}
});
Where process.env.REDIS_URL is rediss://<details>
I couldn't find the root problem. But after comment of Chris, I checked again Heroku Redis addons I used.
Heroku Redis gives me an instance from amazonaws.com, and Redis Enterprise Cloud gives me an instance from redislabs.com. When I added and used Redis Enterprise Cloud, I could connect to it.
But Heroku Redis's connection problem still is a secret for me.
I am trying to connect to mongoDB Atlas from my nodejs app its giving me the following error:
SERVER STARTED...
listening on port 'http://localhost:8080'
Could not connect to the MongoDB database. Exiting now... { Error: connect ECONNREFUSED 13.234.134.161:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
Also I have whitelisted IP on Mongodb Cloud (Atlas). I set it as 'Access to all' which is: 0.0.0.0/0
Same code is working fine on my local machine.
SERVER STARTED...
listening on port 'http://localhost:8080'
Successfully connected to the MongoDB database
The problem occurs when I am deploying my code to GoDaddy shared linux hosting server and trying to connect from there.
What's making difference...?
My nodejs code is:
app.set('port', process.env.PORT || 8080);
var options = {
useNewUrlParser: true,
useUnifiedTopology: true
}
mongoose.connect(dbConfig.dbUrl, options, function(err){
if(err){
console.log('Could not connect to the MongoDB database. Exiting now...', err);
process.exit();
} else {
console.log("Successfully connected to the MongoDB database");
}
});
const server = app.listen(app.get('port'), function(){
console.log(`SERVER STARTED...\nlistening on port 'http://localhost:${app.get('port')}'`);
});
DB url is as follows:
dbUrl: "mongodb+srv://<USERNAME>:<PASSWORD>#cluster0-qsfll.mongodb.net/<DATABASE>?retryWrites=true&w=majority"
If anyone got the same issue and solved it, please write the solution here. Thanks :).
Just got the same issue.
Try to remove useUnifiedTopology.
Helped for me.
I've been trying to connect my node app to my remote Redis Labs server. I have the endpoint which from what I can discover, is my host and port (host.com:port). I've been trying to connect to the cloud server by using
const redis = require('redis');
const client = redis
.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST)
.on('error', err => console.error('FUCK', err));
client.on('connect', function(err, res) {
console.log('redis is connected!');
});
but I continue to get an error. "Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379"
I'm sure this is a simple fix, but I just don't understand how to get it to work. Any help would be much appreciated!
Figured it out. I knew it was a simple fix. Just had to call client.auth(process.env.REDIS_PASSWORD)
const client = redis.createClient(
process.env.REDIS_PORT,
process.env.REDIS_HOST
);
client.auth(process.env.REDIS_PASSWORD);
i'm trying to connect to my database using MSSQL Server using NodeJS
but i have an error
{ ConnectionError: Failed to connect to 10.10.17.199:undefined in 15000ms
here is the beginning of my code:
var sql = require("mssql");
// config for your database
var config = {
user: 'mat1',
password: 'a',
server: '10.10.17.199\\MSSQLLocalDB',
database: 'master' ,
port: 1433
};
//\\MSSQLLocalDB
console.log("passed 1")
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
what's wrong ?
You are getting an error trying to connect to the server. Maybe you dont have access to the server. Also can happen is timing out to connect, if thats the case you can modify the connection timeout setting in the connection configuration.
my code below
var mongoose = require('mongoose');
for(let i = 0;i<600;i++)
{
let db1 = mongoose.createConnection('mongodb://127.0.0.1:27017/abc');
db1.on('error', function(error) {
console.log("error = "+(i)+" "+error +db1);
});
db1.on('close', function() {
console.log("close = "+(i)+" "+db1);
});
db1.once('open', function() {
"use strict";
// db1.close();
});
}
I wanted to test mongodb ,the result is
error = 364 MongoError: failed to connect to server [127.0.0.1:27017] on first connect[object Object]
error = 365 MongoError: failed to connect to server [127.0.0.1:27017] on first connect[object Object]
error = 385 MongoError: failed to connect to server [127.0.0.1:27017] on first connect[object Object].......
Another question is whether the connection needs to be closed?
thanks.
Make sure that you have Mongo running on on port 27017 of the same computer that your Node app is running. To verify that, run this in the command line:
mongo localhost:27017
You don't need to close the connection and open it multiple times. You should open the connection once in your app and close it only when you want to close your app. See those answers for more datails:
Where to initialize a new database connection in nodejs?
Using mongoDB in Express routers