简体   繁体   中英

Error in connecting to SQL Server Database in Node js?

I am learning how to use Node js with sql server database. I am trying to connect to a sql server database but there is this problems that I am having when I enter the server ip address in my databaseconfiguration in node js. Kindly can anyone help me to fix the error. This is the connection string that my dbadmin has given me.

<add name="ElmaReport" connectionString="Data Source=172.20.3.32\SQL2015;Initial Catalog=ElmaTest;User ID=realm;password=friend" providerName="System.Data.SqlClient" />

I am trying to use this connection string in my node js database configuration.

var sql = require('mssql');
var addr = "172.10.3.22/SQL2014"; //This is where the error is.It doesn't understand the '/' character.
var config = {
    "server":addr,
    "user": "realm",
    "password": "friend",
    "database": "ElmaTest"
};

sql.connect(config, function (err) {

    if (err) console.log(err);


});



var updateMember = function( username, password) {
    return sql.execute( {
        procedure: "updateMember",
        params: {

            firstName: {
                type: sql.NVARCHAR,
                val: username
            },
            lastName: {
                type: sql.NVARCHAR,
                val: password
            }
        }
    } );
};

function  connecttoDb() {

  //  updateMember("elma","pass1234");
    sql.connect(config, function (err) {

        if (err) console.log(err);


    });


}

module.exports.datavalue = connecttoDb();

From the mssql package documentation (within the examples):

You can use 'localhost\\\\instance' to connect to named instance

Of course you'll have to replace "localhost" with your server address and "instance" with your SQL Server instance name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM