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

13,026

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.

Share:
13,026
Pratik Gaikwad
Author by

Pratik Gaikwad

I am a full time student pursuing Master's degree in Computer Science(M.S.) in Stevens Institute of Technology, Hoboken, New Jersey, USA. I have worked as software developer for more than 4 years with Tata Consultancy Services. During my professional tenure I've worked in below technologies: .Net framework(4.0,4.5), ASP.NET(web form, MVC), JQuery(Core, UI), NodeJS, Angular, Typescript, HTML, CSS, WCF, SQL

Updated on June 07, 2022

Comments

  • Pratik Gaikwad
    Pratik Gaikwad almost 2 years

    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.

    • mugabits
      mugabits about 8 years
      Have you tried using the actual server name rather than (.) for localhost?
    • Pratik Gaikwad
      Pratik Gaikwad about 8 years
      @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.
    • mugabits
      mugabits about 8 years
      try SELECT @@SERVERNAME after you login in your instance of sql server.
    • Pratik Gaikwad
      Pratik Gaikwad about 8 years
      @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;Vers‌​ion;11.0.2100.60;tcp‌​;1433;np;\\DELL\pipe‌​\sql\query;; Without instance name all I am getting is "Undefined"
  • Pratik Gaikwad
    Pratik Gaikwad about 8 years
    @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.
  • Damodar Bashyal
    Damodar Bashyal about 4 years
    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.