【发布时间】:2017-01-19 20:01:07
【问题描述】:
我正在尝试使用我的sails.js 项目连接到SQL Server 数据,并且我使用mssql 连接到数据库。
我没有任何命名实例,并且我正在使用 Windows 身份验证登录,到目前为止我在 testController.js 中编写的代码是
/**
* testController
*
* @module :: Controller
* @description :: A set of functions called `actions`.
*
* Actions contain code telling Sails how to respond to a certain type of request.
* (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
*
* You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
* and/or override them with custom routes (`config/routes.js`)
*
* NOTE: The code you write here supports both HTTP and Socket.io automatically.
*
* @docs :: http://sailsjs.org/#!documentation/controllers
*/
module.exports = {
/**
* Action blueprints:
* `/new/index`
* `/new`
*/
index: function(req, res) {
var config = {
// user: '(local)',
// password: '',
//server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
server: '192.168.0.109', // You can use 'localhost\\instance' to connect to named instance
database: 'test',
options: {
//encrypt: true // Use this if you're on Windows Azure
trustedConnection: true,
// port: 1444
}
}
var sql = require('mssql');
var connection = new sql.Connection(config, function(err) {
if (err) {
console.log("Error opening the connection!", err);
return;
}
conn.queryRaw("SELECT TOP 10 FirstName, LastName FROM Person.Person", function(err, results) {
if (err) {
console.log("Error running query!");
return;
}
for (var i = 0; i < results.rows.length; i++) {
console.log("FirstName: " + results.rows[i][0] + " LastName: " + results.rows[i][1]);
}
});
});
},
_config: {}
};
但它会触发错误
打开连接时出错! { [ConnectionError: 用户 '' 登录失败。]
名称:“连接错误”,
message: '用户\'\'登录失败。',
代码:'ELOGIN' }
我真的很困惑,不知道在哪里可以找到带有windows authentication 的文档,我只能找到trustedConnection: true,
请就这个问题指导我。
谢谢
【问题讨论】:
标签: sql-server node.js sql-server-2008 sails.js