【发布时间】:2016-02-16 01:00:24
【问题描述】:
您好,我无法连接到在节点 js 中使用 Windows 身份验证的 SQL Server。我正在使用 mssql 模块。错误信息是:
[ConnectionError: Login failed for user ''. The user is not associated with a trusted SQL Server connection.]
name: 'ConnectionError',
message: 'Login failed for user \'\'. The user is not associated with a trusted SQL Server connection.',
code: 'ELOGIN' }
这是我的代码:
config = {
server : "localhost\\MSSQLSERVER",
database : "mydatabase",
port : 1433
}
function loadDepts() {
var conn = new sql.Connection(config);
var request = sql.Request(conn);
conn.connect(function(err) {
if (err) {
console.log(err);
return;
}
request.query("select deptid, deptname from departments", function(err, table) {
if (err) {
console.log(err);
return;
}
else {
console.log(table);
}
conn.close();
});
});
}
loadDepts();
【问题讨论】:
-
你把用户名放在哪里了?
-
我没有输入用户名,因为我的 SQL Server 的身份验证方法是 Windows 身份验证。在 .Net 中,这就是我定义连接字符串的方式:“Server=localhost;Integrated Security=SSPI;Database=mydatabase”。不知道如何在 Node.js 中实现类似的东西。
-
哦,我使用 sa 帐户通过 SQL 服务器身份验证对其进行了测试,并且它可以正常工作。但我需要的是让它在 Windows 身份验证中工作。
标签: sql-server node.js npm