【发布时间】:2018-03-29 03:51:07
【问题描述】:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
var sql = require('mssql/msnodesqlv8');
var config = {
driver: 'msnodesqlv8',
connectionString: 'Driver={SQL Server Native Client 11.0};Server=DESKTOP-QUUGSCT\SQLEXPRESS;Database=nodedb;Trusted_Connection=yes;',
// CONNECTION_NAME = "Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog="CatalogName";Data Source="Production_Server_Name;""
};
const pool = new sql.ConnectionPool(config).connect().then(pool => {
return pool.request().query("Select * From dbo.test")
}).then(result => {
let rows = result.recordset
res.status(200).json(rows);
sql.close();
}).catch(err => {
res.status(500).send({ message: `${err}` })
sql.close();
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});
我用这段代码nodejs在windows认证模式下连接MSSql连接字符串。我尝试运行这个程序我得到了这样的错误
{
"message":"ConnectionError: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. "
}
我启用了所有管道和 tcp 端口。
【问题讨论】:
-
检查是否允许远程连接到此服务器?
-
是的,我的 MSSQL Server 2016 中允许远程连接
-
sql server 浏览器启动
-
是的,我开始了..
-
var edge = require('edge'); var params = { connectionString: "Server=DESKTOP-QUUGSCT\SQLEXPRESS;Database=tempdb;Integrated Security=True", source: "Select * From dbo.test" }; var getData = edge.func('sql', params); getData(null, function (error, result) { if (error) { console.log(error); return; } if (result) { console.log(result); } else { console.log("No results") ; } });
标签: sql-server node.js sql-server-2016