Good day. There is a database, server MYSERVER on SQL Server 2012 Express, Windows authentification. Used by Node.JS tools for Visual Studio 2015.

Trying to connect from Node.JS:

var edge = require('edge'); var params = { connectionString: "Server=local\\MYSERVER;Database=mydb_2012;Integrated Security=True", source: "Select * from MyTable" } var getData = edge.func('sql', params); var obj, obj_; getData(null, function (error, result) { obj = error; obj_ = result; if (error) { console.log(error); return; } if (result) { console.log(result); } else { console.log("No results"); } }); 

In the end, nothing happens.

Tried another mssql, the same thing:

 var sql = require("mssql"); var config = { driver: 'msnodesqlv8', server: 'localhost\\MYSERVER', database: 'mybase_2012', options: { trustedConnection: true, useUTC: true } } 

    1 answer 1

    You need the module ' npm install msnodesql ' , then:

    var sql = require ('msnodesql');
    var conn_str = "Driver = {SQL Server Native Client 12.0}; Server = localhost \\ MYSERVER; UID =; PWD =; Database = 'mybase_2012';";
    sql.open (conn_str, function (err, conn) {
    if (err)
    {console.log ("Error opening the connection!"); return; }
    else console.log ("Successfuly connected");
    conn.queryRaw ("SELECT .....

    • And if there are two SQL server instances on the server (workstation) (and you need to contact one of them), then the correct syntax will probably be, instead of Server = MYSERVER - Server = localhost \\ MYSERVER (MYSERVER is the name of the SQL server , not a computer)? - user211576 2:01 pm
    • Database should not be in curly brackets? And should not be written Trusted Connection = Yes (or {Yes}) - user211576
    • Not. npm install msnodesql crashes with an error - user211576
    • The driver for MSSQL needs to be installed differently. Here it is written: microsoft.com/en-us/download/details.aspx?id=29995 - olegchap
    • no, it does not work - user211576