Can not connect to the database
See original GitHub issueHi,
I am having problems creating a connection string that works.
Server version: SQL Server 2014 Express.
I can login to SQL Management Studio with the same credentials. Server name: (local)\SQLEXPRESS2014 User: test Pass: testtest
To login with nodejs i tried this:
var sql = require('mssql');
var config = {
connectionString: 'Server=(local)\\SQLEXPRESS2014;Database=test-server;UID=test;PWD=testtest;',
};
var connection = new sql.Connection(config);
connection.connect(function(err) {
console.log(err); // This is always getting hit
});
That however returns the following error:
{ [ConnectionError: Failed to connect to undefined:1433 - connect ECONNREFUSED 127.0.0.1:1433] name: ‘ConnectionError’, message: ‘Failed to connect to undefined:1433 - connect ECONNREFUSED 127.0.0.1:1433’, code: ‘ESOCKET’ }
Same error if i change the config to:
var connection = new sql.Connection({
user: 'test',
password: 'testtest',
server: '(local)\\SQLEXPRESS2014', // or localhost\\SQLEXPRESS2014
database: 'test-server'
});
Somehow it does not translate the connection correctly.
(My file only contains the first lines at the top to connect. Otherwise it’s completely empty. I wanted to get the connection to work before writing any other code.)
Issue Analytics
- State:
- Created 7 years ago
- Comments:6

Top Related StackOverflow Question
This is how you should do it, if you’re connecting to named instance. http://stackoverflow.com/questions/21204411/connect-to-sql-server-with-mssql-for-node-js
@harshavarun25 Yes, you need access to the server as well as to the database. encrypt option is only for the connection encryption, unrelated to the problem.