简体   繁体   English

Nodejs mssql ConnectionError:用户“ ”登录失败

[英]Nodejs mssql ConnectionError: Login failed for user ' '

This is my code:这是我的代码:

var sql = require("mssql");

var dbConfig = {
server: "server",
username: "user",
password: "password",
database: "database"
};

function getEmp() {
var conn = new sql.Connection(dbConfig);
console.log(conn);
var req = new sql.Request(conn);
conn.connect(function (err) {
    if (err) {
        console.log(err);
        return;
    }
    req.query("SELECT * FROM Alg.User", function (err, recordset) {
        if (err) {
            console.log(err);
            return;
        }
        else {
            console.log(recordset);
        }
        conn.close();
    });
});
}

getEmp();

And this is the error I'm logging:这是我记录的错误:

 { ConnectionError: Login failed for user ''.
at Connection.<anonymous> (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\mssql\lib\tedious.js:378:25)
at Connection.g (events.js:291:16)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Connection.processLogin7Response (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:672:16)
at Connection.message (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:1082:21)
at Connection.dispatchEvent (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:519:45)
at MessageIO.<anonymous> (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:439:23)
at emitNone (events.js:86:13)
at MessageIO.emit (events.js:185:7)
name: 'ConnectionError',
message: 'Login failed for user \'\'.',
code: 'ELOGIN' }

Anyone knows what I'm doing wrong?有谁知道我做错了什么? It looks like my variable username isn't put in the connectionstring?看起来我的变量用户名没有放在连接字符串中? But I have no idea why...但我不知道为什么...

Thanks in advance!提前致谢!

Solution:解决方案:

The problem was that in dbConfig, the username variable should be changed to user!问题是在 dbConfig 中,用户名变量应该更改为 user! And the sql query was wrong also, it should have been [Alg].[User], because 'User' is a keyword!而且sql查询也错了,应该是[Alg].[User],因为'User'是关键字!

Using tedious / msnodesqlv8 driver for Windows worked for me:为 Windows 使用乏味的 / msnodesqlv8 驱动程序对我有用

Instead of:代替:

var sql = require("mssql");

I changed it to:我把它改成:

var sql = require("mssql/msnodesqlv8");

I did not hard code user name/password.我没有硬编码用户名/密码。

Here's what my dbconfig looks like:这是我的 dbconfig 的样子:

var db_config = {
  driver: "msnodesqlv8",
  server: "ServerName",
  database: "databaseName",
  options: {
    trustedConnection: true,
    useUTC: true
  }
}

Please make "username" to "user" in your configuration.请在您的配置中将“用户名”改为“用户”。 If you try to console.log(conn), you will see that configuration is using "user" instead of userName.如果您尝试使用 console.log(conn),您将看到配置使用的是“user”而不是 userName。

I have answered this question, please refer to SQL Server Error "[ConnectionError: Login failed for user '****'.] "while connecting SQL Server with Nodejs using MSSQL我已经回答了这个问题,请参考SQL Server 错误“[ConnectionError: Login failed for user '****'.] 使用 MSSQL 将 SQL Server 与 Nodejs 连接起来

For google viewers...对于谷歌观众...

If the above solution doesn't work for you.如果上述解决方案对您不起作用。 You should check the SQL Server Browser in Computer services is running as this is what processes the requests to the server.您应该检查计算机服务中的 SQL Server Browser 是否正在运行,因为这是处理对服务器的请求。

That one stumped me for a while那个让我难倒了一阵子

将 dbConfig 的“用户名”更改为“用户”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 MSSQL 将 SQL Server 与 Nodejs 连接时出现 SQL Server 错误“[ConnectionError: Login failed for user &#39;****&#39;.] - SQL Server Error "[ConnectionError: Login failed for user '****'.] "while connecting SQL Server with Nodejs using MSSQL nodejs 中的 mssql 使用快速服务器返回用户 {capped username} 登录失败 - mssql in nodejs is returning Login failed for user {capped username} using express server 节点续集 (MSSQL) - 用户 &#39;&#39; 登录失败 - Node Sequelize (MSSQL) - Login failed for user '' 节点js中用户的MSSQL连接登录失败 - MSSQL Connection login failed for user in node js 使用pdo的mssql登录失败,用户“ dbo”登录失败 - mssql using pdo fail login getting Login failed for user 'dbo' 用户使用PHP连接登录连接到MSSQL数据库失败 - Connecting to a MSSQL database with PHP Connection Login failed for user 从远程计算机连接到 mssql 服务器导致用户“登录失败” - Connecting to an mssql server from a remote machine gives Login failed for user '' Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED - Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED 从 Oracle SQL Developer 连接 MSSQL 数据库时,由于用户错误登录失败 - 在 MAC Catalina 中 - Login Failed For User Error while connected with MSSQL Database from Oracle SQL Developer - in MAC Catalina MAMP mssql_connect()返回登录失败 - MAMP mssql_connect( ) returning login failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM