Unable to connect to SQL Server database using mssql and expressjs - node.js

I am trying to connect to a SQL Server database from expressjs using mssql, but I keep getting this:
I am following the example from https://www.npmjs.com/package/mssql#connections-1
The code in my app.js is as follows
const config = {
//user: '',
//password: '',
server: 'LAPTOP-A7INMDKJ',
database: 'dbone'
}
sql.on('error', (err)=> {
// error handler
});
sql.connect(config).then(
(pool) =>{
return pool.request()
.query('select * from course');
}).
then(result=> {
console.log('dasdasdsa');
console.log(result);
}).
catch( (err)=>{
console.log(err);
});
I Component services I have this
and in computer management tcp/ip is enabled
What am I doing wrong? I am using Windows authentication for SQL Server.

The normal troubleshooting process is to verify:
SQL Server has TCP/IP enabled and is configured to listen on port 1433 in Configuration Manager.
SQL Server is running and the SQL Server Error log has an entry like Server is listening on [ 'any' <ipv4> 1433].
The Windows Firewall is not blocking inbound TCP connections on port 1433
The client can resolve the SQL Server's hostname correctly
The client can connect over TCP/IP to port 1433 on the SQL Server, eg by powershell's Test-NetConnection -ComputerName [sqlserverhostname] -Port 1433

Related

How to connect to a rethink db hosted on centos?

I have my rethink db hosted in centos and proxied port 8080 to a domain name using nginx.
From my local pc, how do I connect my app to the server?
you need to open 28015 port on your centos server, than you can connect to rethinkdb listening on 28015 port of your centos server via this connection string
r = require('rethinkdb')
r.connect({ host: 'centos.example.org', port: 28015 }, function(err, conn) {...});
where centos.example.org is hostname/ip of your server.
its worth notice that you should either whitelist your IP in firewall (so, only connections from your home IP is allowed), or install authorization and tls certs on rethinkdb server.
this documents can help -
https://rethinkdb.com/docs/install/centos/
https://rethinkdb.com/docs/start-a-server/

connection error while connecting to AWS DocumentDB

getting the following error while connecting to AWS DocumentDB from node.js
connection error: { [MongoNetworkError: connection 1 to
docdb-2019-01-28-06-57-37.cluster-cqy6h2ypc0dj.us-east-1.docdb.amazonaws.com:27017
timed out] name: 'MongoNetworkError', errorLabels: [
'TransientTransactionError' ] }
here is my node js file
app.js
var mongoose = require('mongoose');
mongoose.connect('mongodb://abhishek:abhishek#docdb-2019-01-28-06-57-37.cluster-cqy6h2ypc0dj.us-east-1.docdb.amazonaws.com:27017/?ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0', {
useNewUrlParser: true
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("connected...");
});
By default aws documentdb is designed to connect only from same VPC.
So to connect nodejs application from an ec2 in same vpc. You need to have the pem file as by default SSL is enabled while db instance is created.
step-1 : $ wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem in required directory
step-2 : Change the mongoose connection with options pointing to pem file
mongoose.connect(database.url, {
useNewUrlParser: true,
ssl: true,
sslValidate: false,
sslCA: fs.readFileSync('./rds-combined-ca-bundle.pem')})
.then(() => console.log('Connection to DB successful'))
.catch((err) => console.error(err,'Error'));
Here am using mongoose 5.4.0
To connnect from outside the VPC, please try to follow the below doc from aws:
https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html
Personally I tried only to connect from VPC and it worked fine.
Update =====:>
To connect from Robo 3T outside VPC please follow the link -
AWS DocumentDB with Robo 3T (Robomongo)
to use AWS DocumentDB outside VPC for example your development server EC2 or from the local machine will get a connection error unless you use ssh tunneling or port forwarding
and about tunneling it simple
use this command in your local
ssh -i "ec2Access.pem" -L 27017:sample-cluster.node.us-east-1.docdb.amazonaws.com:27017 ubuntu#EC2-Host -N
in application configuration use
{
uri: 'mongodb://:#127.0.0.1:27017/Db',
useNewUrlParser: true,
useUnifiedTopology:true,
directConnection: true
}
just make sure you can connect from this tunneling ec2 and database
and if you decide to use port forwarding
steps
0- in ec2 security grou[p add inbound role with custom TCP and port 27017 All traffic
1- go to your ec2 instance and install Haproxy
$ sudo apt install haproxy
2- edit Haproxy configuration
$ sudo nano haproxy.cfg
3- in end off file add
listen mongo
bind 0.0.0.0:27017
timeout connect 10s
timeout client 1m
timeout server 1m
mode TCP
server AWSmongo <database-host-url>:27017
4- now restart HaProxy
$ sudo service HaPoxy restart
5- now you can access your database using
{uri: 'mongodb://<database-user>:<database-pass>#<EC2-IP>:27017/<db>'}

RethinkDB error when connect to live server on AWS

Connecting to local server is working fine. But i have to maintain one centralized DB for my team. I setup rethinkdb on aws server and have to access this from local from each system in my local project
app.use(function(req,res,next){
r.connect({
host: '55.52.57.59',
port: 28015,
db: 'league'
},function(err,conn){
if (err) throw err;
req['app_conn']=conn;
next();
});
});
what could i do? Please help me!
Check whether you have opened 28015 port on AWS Server or not?

Cannot run my Electron App without internet connection

I have an Electron App which connects to an instance of a sql server(Microsoft SQL Server 2012) on my local machine using npm module mssql.The app works fine when connected to the internet, however I get the following error when offline.
"Failed to connect to DELL:undefined - getaddrinfo ENOENT DELL:48988"
following is the config:
var dbconfig = {
server: 'DELL\\INSTANCENAME',
database: 'myDB',
user: 'username',
password: 'password'
port: 1433
};
I have also made sure of the following:
1. TCP/IP protocol is enabled
2. SQL Server INSTANCE/Server Agent and Server Browser is enabled
Since what I'm building is a desktop app, I do not want any dependency with internet connection. Not sure what I'm missing.... please suggest.

Node connecting to Mongodb in my VPS with port 27017, no if I change the port

I've got a Digital Ocean VPS, and followed their tutorial:
link
It's working the app.js and connecting to the database.
Here is the code of the apps file:
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) {
if (err) {
throw err;
} else {
console.log("successfully connected to the database");
}
db.close();
});
But if I change the port 127.0.0.1:27017 to 127.0.0.1:3500 the one I want to connect, it's not working.
Here is my ufw
ufw allow 22/tcp
ufw allow 3500/tcp
ufw allow 80/tcp
ufw allow 27017/tcp
Any help?
Thank you
Man, you did a bad thing. You opened MongoDB to whole world. If your node.js app is on the same server with MongoDb, then no reasons to open 27017 & 3500 for internet. Close these ports ASAP.
Why do you think that you changed mongoDb port? Please show mongoDb config file with port configuration row. Also after you changed the mongodb config file it requires restart mongodb servic/daemon.

Resources