使用mssql连接sqlserver问题,疑惑很久..
发布于 9 年前 作者 zzwwjjdj319 4119 次浏览 最后一次编辑是 8 年前 来自 问答

-----------第一种方式可以连接----------- var sql = require(‘mssql’); sql.connect(“mssql://sa:123456@localhost/admanager”).then(function() { // Query new sql.Request().query(‘select * from XRuserSet’).then(function(recordset) { console.dir(recordset); }).catch(function(err) { // … query error checks }); }).catch(function(err) { // … connect error checks }); untitled1.png

-----------第二种方式为什么不行?-------------------- var sql = require(‘mssql’);

var config = { user: ‘sa’, password: ‘123456’, server: ‘localhost’, // You can use ‘localhost\instance’ to connect to named instance database: ‘admanager’,

options: {
    encrypt: true // Use this if you're on Windows Azure
}

}

sql.connect(config, function(err) { var request = new sql.Request(); request.query(‘select * from XRuserSet’, function(err, recordset) { console.dir(recordset); }); }); sql.on(‘error’, function(err) { });

–报错 { [ConnectionError: Failed to connect to 10.81.36.167:1433 in 15000ms] name: ‘ConnectionError’, message: ‘Failed to connect to 10.81.36.167:1433 in 15000ms’, code: ‘ETIMEOUT’ }

** 求高手帮忙**

回到顶部