Timeout error while connecting to SQL Server: Connection Error: Failed to connect to servername\instancename in 15000ms - sql

The error code is code ETIMEOUT. I am using SQL Server 2014, NodeJs version v12.16.2 and I am running this code in Visual Studio Code.
I have created the database and the table is also created with some records. For the server name, I have also tried giving the FQDN, but it didn't work.
This is the code snippet:
const express = require('express');
const app = express();
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
app.get('/', function(req, res) {
res.send('<hHii</h');
});
const sql = require('mssql');
var config = {
user: 'domain\username',
password: 'mypwd',
server: 'servername',
host: 'hostname',
port: '1433',
driver: 'tedious',
database: 'DBname',
options: {
instanceName: 'instancename'
}
};
sql.connect(config, function(err) {
if (err)
console.log(err);
let sqlRequest = new sql.Request();
//var sqlRequest = new sql.Request(connection)
let sqlQuery = 'SELECT * from TestTable';
sqlRequest.query(sqlQuery, function(err, data) {
if (err) console.log(err);
console.log(data);
//console.table(data.recordset);
// console.log(data.rowAffected);
//console.log(data.recordset[0]);
sql.close()
});
});
const webserver = app.listen(5000, function() {
console.log('server is up and running....');
});
Error:
tedious deprecated The default value for `config.options.enableArithAbort` will change from `false` to `true` in the next major version of `tedious`. Set the value to `true` or`false` explicitly to silence this message.
node_modules\mssql\lib\tedious\connection-pool.js:61:23
server is up and running....
ConnectionError: Failed to connect to servername\instantname in 15000ms
at Connection.<anonymous(..\SQL\Sample\sample\node_modules\mssql\lib\tedious\connection-pool.js:68:17)
at Object.onceWrapper (events.js:417:26)
at Connection.emit (events.js:310:20)
at Connection.connectTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1195:10)
at Timeout._onTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1157:12)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
code: 'ETIMEOUT',
originalError: ConnectionError: Failed to connect to INPUNPSURWADE\DA in 15000ms
at ConnectionError (..\SQL\Sample\sample\node_modules\tedious\lib\errors.js:13:12)
at Connection.connectTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1195:54)
at Timeout._onTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1157:12)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
message: 'Failed to connect to servername\instantname in 15000ms',
code: 'ETIMEOUT'
},
name: 'ConnectionError'
}
ConnectionError: Connection is closed.
at Request._query (..\SQL\Sample\sample\node_modules\mssql\lib\base\request.js:462:37)
at Request._query (..\SQL\Sample\sample\node_modules\mssql\lib\tedious\request.js:346:11)
at Request.query (..\SQL\Sample\sample\node_modules\mssql\lib\base\request.js:398:12)
at Immediate.<anonymous(..\SQL\Sample\sample\index.js:43:12)
at processImmediate (internal/timers.js:458:21) {
code: 'ECONNCLOSED',
name: 'ConnectionError'
}

Go to Start menu in Windows, search for "Services" and open it.
Look for "SQL Server Browser"
Right click on it and go to Properties.
Switch "Start up type" to "Automatic"
Click Ok
Right click on it again and Start the service.
It should work after that!

You might make a typo in host/port, or the server doesn't listen external interfaces (it might be configured to liten 127.0.0.1 only)
to check that the server is listening to incoming connections, run in terminal the following:
telnet <hostname> <port>
(mac/linux only)
If it says "Unable to connect to remote host: Connection refused" it means the host is there but it doesn't listen the port.
If it says "Unable to connect to remote host: Connection timed out" then the host might not be there, ot doesn't listen to the port.
You may also want to check if your firewall allows connection to that server.

Related

mssql in nodejs not connecting

Trying to connect to my database to create a local website but having connection issues.
Running in node.js, this is my server.js file:
let sql = require('mssql');
let config = {
user: 'sa',
password: 'password',
server: '10.0.1.130\\SQLSERVER',
database: 'MY_DB',
};
function connect() {
let dbConn = new sql.ConnectionPool(config);
dbConn.connect()
}
connect();
Upon running this I get the following error:
ConnectionError: Failed to connect to 10.0.1.130:undefined - self signed certificate
code: 'ESOCKET'
Not sure why it is removing \SQLSERVER but that seems to be my issue.
I know the credentials are all correct as I connect to this on another computer (ubuntu) but its being removed and we want to move it to windows, have not been able to connect to this point.
Any suggestions are appreciated.

Postman does not recognize the server socket.io in postman using express

I've been struggling with a problem for a few hours but I can't figure it out. I tried to look for other answers on stackoverflow but they didn't help me
I want to make a socket server using express
I tried to connect in this way
const server = app.listen(
process.env.PORT || 5050,
console.log(
`Server running in`,
`${process.env.ENV}`.yellow.bold || 'Development'.yellow.bold,
`Mode on Port`,
`${process.env.PORT}`.cyan.bold || `5050`.cyan.bold
)
);
var io = require('socket.io')(server);
console.log(io)
io.on('connection', function (socket) {
console.log('A user connected');
socket.on('disconnect', function() {
console.log('A user disconnected');
});
});
I tried the other methods with http.createServer and many others but they didn't work.
If I log in to the client, I get the error 'cannot get /socket/' and in postman it gives me connection refused
am i doing something wrong?
I use version 4.0 as a socket

Having troubles connecting sequelize with SQL Server

I'm experiencing some stupid problem while connecting sequelize with SQL Server and the error that is thrown looks something like this :
(node:13096) UnhandledPromiseRejectionWarning: SequelizeConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at ConnectionManager.connect (E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:138:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async ConnectionManager._connect (E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)
at async E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32
at async ConnectionManager.getConnection (E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)
Here is my configuration for sequelize code :
module.exports = {
//host: "localhost",
database: "testdb",
//server : 'localhost',
dialectModulePath: 'sequelize-msnodesqlv8',
dialect: "mssql",
port : 1433,
dialectOptions : {
//encrypt: true,
InstanceName : "MSSQLSERVER",
//connectionString : 'Server=localhost\MSSQLSERVER01;Database=master;Trusted_Connection=yes;'
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
As you can see I've tried changing connection string, host, server but the error is still the same. I've also tried enabling TCP/IP for SQL Server and it hasn't worked either.
What am I missing? I don't have a username nor password so I don't think it may be a problem in this case.

peerjs working on loaclhost but not on heroku?

I'm running my node server on 3000 port and peer server on port 3001.In this scenario its working properly.But when deployed over heroku i'm running my server at 3000 and peer server over 443. In this scenario peerjs not wroking. It might be port alloction issue i guess but i'm unable to find the issue.
peer.js
const myPeer = new Peer( {
secure:true,
host: 'my-app-name.herokuapp.com',
port: 443
})
server.js
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
github link to project : link
New to Heroku. Any help will be appreciated!
Add this to your server file:
var ExpressPeerServer = require("peer").ExpressPeerServer;
var options = {
debug: true,
allow_discovery: true,
};
let peerServer = ExpressPeerServer(server, options);
app.use("/peerjs", peerServer);
And call on client side like this:
var peer = new Peer({
host: "yoursite.herokuapp.com",
port: "",
path: "/peerjs",
});
You Have to Host Two Apps on Heroku. First Your Main App and Second Your PeerJS Server. Because You Cannot Host your App On different Port (i.e. https://your-app-name.herokuapp.com:5000). And Then You can Connect Your Main App PeerJS Client With Your PeerJS Server by using this.
const myPeer = new Peer( {
secure:true,
host: 'my-peerjs-server-name.herokuapp.com',
port: 443
})
Happy Coding!
Just use this Heroku Element to deploy your own peer server with zero configuration. Connect to it from your client providing the host attribute as the url of your Heroku app without the https:// part and you may need to also set secure to true.
{
host: "you_app_name.herokuapp.com", // exclude protocol
secure: true
}
add this in server(index,app) file
const { ExpressPeerServer } = require("peer")
const peerServer = ExpressPeerServer(server, {
debug: true
})
app.use("/peerjs", peerServer);
and in client side add this
const myPeer = new Peer(undefined, {
path: "/peerjs",
host: "/",
port: "443",
})
port should same as your server.listen(port)
This will give invalid frame header for socket io but its fine

Error: Timed out while waiting for handshake

I am using scp2 to copy a file to targetPath. config contains host, username, privateKey, path and port.
const client = require('scp2');
export function scpAsync(config, targetPath) {
return new Promise((resolve, reject) => {
client.scp(config, targetPath, err => {
if (!err){
resolve();
} else {
const errorMessage = err;
reject(errorMessage);
}
});
});
}
When doing so I am getting the error:
Error: Timed out while waiting for handshake
I tried to pass also
promptForPass: false
but it did not change anything. Besides that I used debug mode which told me that I am connected to the server and I put a higher setTimeout but then the error is just coming later. I was checking the documentation of scp2 and their GitHub. I use the function like explained there (https://www.npmjs.com/package/scp2) and regarding the error they could fix it with an higher setTimeout (https://github.com/spmjs/node-scp2/issues/107). I tried with a local ftp server, ngrok and ftp on ec2 instance. All with the same problem.
I would be happy to get help. I asked this question also on superuser but did not get an answer:
https://superuser.com/questions/1576964/error-timed-out-while-waiting-for-handshake