Search code examples
node.jssql-servervisual-studioget

error: "Failed to connect to *** - getaddrinfo ENOTFOUND" using postman with a get statement of "http://localhost:9000/Product"


I am struggling making a connection to my ms sql db. I have my config setup like this: exports.dbConfig = { user: "sa", password: "****", server: "UCPRC-ROCK-4/DAVIDSQL", database: "****", port: 1433 };

However when I try to connect it can't find my DB, throwing the error "getaddrinfo ENOTFOUND UCPRC-ROCK-4/DAVIDSQL". I am working locally and I have checked to make sure all services, and dbconfigurations are setup properly.

I try to create a connection as followed: `exports.executeSql = function (sql, callback) { //executes sql function

var conn = new sqlDB.ConnectionPool(settings.dbConfig);//new connection

conn.connect() //open connection
     .then(function () {//if susceful connection proceded here
        var req = new sqlDB.Request(conn); //a request to the db
        req.query(sql)
            .then(function (recordset) {//if the req is a success execute this function
                callback(recordset);
            })
            .catch(function (err) {//if the request is an error then we come here and throw err
                console.log(err);
                callback(null, err);
        });
    })
    .catch(function (err) { //if there is an error connecting to db
        console.log(err);
        callback(null, err);
    });

};`

Is there something I am doing wrong


Solution

  • Named instance should be separated with a "\", not a "/".
    Please try:

    exports.dbConfig = {
        user: "sa",
        password: "****",
        server: "UCPRC-ROCK-4\\DAVIDSQL",
        database: "****",
        port: 1433
    };