简体   繁体   English

尝试从Node.js连接到SQL Server Express

[英]Trying to connect to SQL Server Express from Nodejs

I have installed SQL Server Express and have configured such that TCP/IP, Named Pipes, and Shared Memory are all enabled. 我已经安装了SQL Server Express,并进行了配置,以使TCP / IP,命名管道和共享内存全部启用。 I have also enabled the "sa" user account and set the password to "password". 我还启用了“ sa”用户帐户,并将密码设置为“ password”。 I can login/connect to the SQL Server just fine if I use SMSS. 如果使用SMSS,则可以正常登录/连接到SQL Server。 However, when I try to connect via my code, it keeps telling me that my login has failed. 但是,当我尝试通过代码连接时,它总是告诉我登录失败。

"databaseConfig": {
        "user": "sa",
        "password": "password",
        "server": "localhost",
        "database": "Test",
        "port": 1433
    }

const connection = new sql.ConnectionPool(databaseConfig);
    return connection.connect().then((pool) => {
        let request = pool.request();
        request = request.input('username', sql.VarChar, username);
        ...
    });

So, whenever I try to connect using something similar to what I posted above, I get the following error. 因此,每当我尝试使用类似于上面发布的内容进行连接时,都会出现以下错误。 Really not sure what's wrong here as I believe I setup everything correctly. 真的不确定在这里出了什么问题,因为我相信我正确设置了所有内容。

(node:12228) [DEP0064] DeprecationWarning: tls.createSecurePair() is deprecated. Please use tls.TLSSocket instead.
(node:12228) UnhandledPromiseRejectionWarning: ConnectionError: Login failed for user 'sa'.
    at Connection.tedious.once.err (node_modules\mssql\lib\tedious.js:216:17)
    at Object.onceWrapper (events.js:286:20)
    at Connection.emit (events.js:198:13)
    at Connection.processLogin7Response (node_modules\tedious\lib\connection.js:1142:16)
    at Connection.message (node_modules\tedious\lib\connection.js:1624:21)
    at Connection.dispatchEvent (node_modules\tedious\lib\connection.js:857:45)
    at MessageIO.<anonymous> (node_modules\tedious\lib\connection.js:751:18)
    at MessageIO.emit (events.js:198:13)
    at ReadablePacketStream.<anonymous> (node_modules\tedious\lib\message-io.js:102:16)
    at ReadablePacketStream.emit (events.js:198:13)
(node:12228) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12228) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Seems you might have tried localhost\\SQLExpress when you connect via SSMS which managed by SQL Browser service to re-direct the connection to particular named instance. 似乎当您通过由SQL Browser服务管理的SSMS连接将连接重定向到特定的命名实例时,您可能尝试了localhost\\SQLExpress

To establish named instance connection without specifying it's name, configure static port ( screenshot here ), and use always that port number in connection string. 要建立命名实例连接而不指定其名称,请配置静态端口( 此处为屏幕截图 ),并始终在连接字符串中使用该端口号。

Note: Same port cannot be used again if you planning to install second instance of SQL Express within same server 注意:如果计划在同一服务器上安装SQL Express的第二个实例,则不能再次使用同一端口

Further troubleshooting steps.. or DBA.SE 进一步的故障排除步骤..DBA.SE

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM