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端口。
答案 0 :(得分:0)
connectionString: 'Driver={SQL Server Native Client 11.0};Server=DESKTOP-QUUGSCT\SQLEXPRESS;Database=nodedb;Trusted_Connection=yes;'
您可能需要更改服务器名称DESKTOP-QUUGSCT\SQLEXPRESS
到DESKTOP-QUUGSCT\\SQLEXPRESS