3

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.

Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44
  • Have you tried using the actual server name rather than (.) for localhost? – mugabits Mar 13 '16 at 06:31
  • @jmugz3 I tried with MSSQLServer, if that is correct. If not, can you point me how to find the server name? With MSSQLServer, I am getting same errors. – Pratik Gaikwad Mar 13 '16 at 06:35
  • try SELECT @@SERVERNAME after you login in your instance of sql server. – mugabits Mar 13 '16 at 06:37
  • @jmugz3, please see the edit I made to the question. I am getting below error after adding instancename: Error: Port for . not found in ServerName;DELL;InstanceName;MSSQLSERVER;IsClustered;No;Version;11.0.2100.60;tcp;1433;np;\\DELL\pipe\sql\query;; Without instance name all I am getting is "Undefined" – Pratik Gaikwad Mar 13 '16 at 06:46

1 Answers1

5

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.

Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44
  • @sqluser you are right. There was issue in connectivity when i was posting this answer. I will update the answer soon as come back online. – Pratik Gaikwad Mar 13 '16 at 12:07
  • Commenting out `// encrypt: true` worked for now. But I guess it's better to have `encrypt=true` if I can find a solution to make it work. – Damodar Bashyal Feb 05 '20 at 05:58