使用NodeJs mssql通过Windows身份验证连接到SQL Server

时间:2016-12-17 01:40:54

标签: sql-server

我需要使用nodeJs连接到SQL Server。这是我通常用于.NET的连接字符串

Data Source=DESKTOP-QPC8N68\SQLEXPRESS;Initial Catalog=ProjectX;Integrated Security=True

我正在使用mssql npm包和我的代码,如下所示:

app.get('/', function (req, res) {
    var sql = require("mssql");

    var config = {
        server: 'localhost\\SQLEXPRESS',
        database: 'ProjectX',

        options: {
            trustedConnection: true
        }
    };

    sql.connect(config).then(function (ar) {
        console.log('connected');
        console.log(ar);
    }).catch(function (ex) {
        console.log(ex);
    });

    res.send('OK');
});

我收到以下错误

  

ConnectionError:无法连接到localhost:在15000ms中未定义
  在Connection。 (C:\ Drive F \ NodeSql \ node_modules \ mssql \ lib \ tedious.js:378:25)
  name:'ConnectionError',
  消息:'无法连接到localhost:在15000ms中未定义',
  代码:'ETIMEOUT'

     

ConnectionError:无法连接到localhost:在15000ms中未定义
  在连接处。
  在ontimeout(timers.js:365:14)
  在tryOnTimeout(timers.js:237:5)   在Timer.listOnTimeout(timers.js:207:5)
  name:'ConnectionError',
  消息:'无法连接到localhost:在15000ms中未定义',
  代码:'ETIMEOUT'

我正在使用Windows身份验证连接到SQL Server。这里缺少什么,你建议连接到SQL Server的npm包是什么?

0 个答案:

没有答案
相关问题