How to connect to SQL Server with windows authentication from Node.JS using mssql module

前端 未结 12 1391
忘掉有多难
忘掉有多难 2020-11-27 13:57

Hi I\'m unable to connect to SQL server that is using windows authentication in node js. I\'m using the mssql module. The error message is :

[ConnectionError         


        
12条回答
  •  天涯浪人
    2020-11-27 14:43

    I could only get a Trusted Connection working using msnodesqlv8 (limited to Windows environments) with a connection string (rather than a config object).

    const sql = require("msnodesqlv8");
    
    const connectionString = function(databaseName) {
        return "Server=.;Database=" + databaseName + ";Trusted_Connection=Yes;Driver={SQL Server Native Client 11.0}";
    }
    
    sql.query(connectionString("DatabaseName"), "SELECT * FROM dbo.Table1" , (err, recordset) => {
        if(err) {
            // Do something with the err object.
            return;
        }
    
        // else
        // Do something with the recordset object.
        return;
    });
    

提交回复
热议问题