Failed to connect to local SQL Server database using Tedious and Node JS

Pratik Gaikwad picture Pratik Gaikwad · Mar 13, 2016 · Viewed 11.3k times · Source

I am trying to connect to SQL Server on my local machine. I am trying to use tedious and tedious-ntlm. The configuration for both is as below:

var tds = require("tedious-ntlm");
//var tds = require("tedious");
var config = {
userName: 'pratikdb',
password: 'pratikdb',
server: '.',
options: {
    database: "TEST",
    debug: {
        packet: false,
        payload: false,
        token: false,
        data: false
    },
    encrypt: true
  }
};


http.createServer(app).listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
    var connection = new tds.Connection(config);
    connection.on('connect', function (err) {
        console.log(err);
    });
});

When I am working with tedious, I am getting this error:

ConnectionError: Failed to connect to .:1433 - getaddrinfo ENOTFOUND . .:1433]
message: 'Failed to connect to .:1433 - getaddrinfo ENOTFOUND . .:1433', code: 'ESOCKET'

When I am working with "tedious-ntlm", I am getting this error:

Connection to .:1433 - failed Error: getaddrinfo ENOTFOUND . .:1433

As mentioned here, I tried using ip of machine even then I am getting same error.

Edit:

When I modified the config as below as per suggestion by @jmugz3:

var config = {
    userName: 'pratikdb',
    password: 'pratikdb',
    server: 'DELL',
    options: {
        instanceName: ".",
        database: "TEST",
        debug: {
            packet: false,
            payload: false,
            token: false,
            data: false
        },
        encrypt: true
    }
};

I am getting error :

Error: Port for . not found in ServerName;DELL;InstanceName;MSSQLSERVER;IsClustered;No;Version;11.0.2100.60;tcp;1433;np;\DELL\pipe\sql\query;;

Can anyone please help me?

Thanks in advance.

Answer

Pratik Gaikwad picture Pratik Gaikwad · Mar 13, 2016

Found an answer tedious discussion. Changed my configuration variable to

var sqlConfig = {
    userName: 'pratikdb', //username created from SQL Management Studio
    password: 'pratikdb',
    server: 'DELL',    //the IP of the machine where SQL Server runs

    options: {
        instanceName: 'MSSQLSERVER',
        database: 'Test',  //the username above should have granted permissions in order to access this DB.
        debug: {
            packet: false,
            payload: false,
            token: false,
            data: false
        },
        //encrypt: true
    }

};

the main points were to look for were uppercasing of server and instanceName. for some reason tedious is maintaining case-sensitivity in both key and value of array.