gpt4 book ai didi

sql-server - sails.js 使用 mssql 中的 SQL Server 数据库配置错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:43 25 4
gpt4 key购买 nike

我正在尝试使用 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: {}

};

但是它触发了错误

Error opening the connection! { [ConnectionError: Login failed for user ''.]
name: 'ConnectionError',
message: 'Login failed for user \'\'.',
code: 'ELOGIN' }

我真的很困惑,不知道在哪里可以找到它的Windows身份验证文档,我能找到的只是trustedConnection: true,

请指导我解决这个问题。

谢谢

最佳答案

我可能这么晚才回答,但 mssql 在使用 Windows Auth 时通常会遇到问题。请改用 Edge.js 建立连接。

关于sql-server - sails.js 使用 mssql 中的 SQL Server 数据库配置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33135212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com