2

I have installed SQL Server Express and have configured such that TCP/IP, Named Pipes, and Shared Memory are all enabled. I have also enabled the "sa" user account and set the password to "password". I can login/connect to the SQL Server just fine if I use SMSS. 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.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
A. L.
  • 73
  • 6

1 Answers1

0

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.

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

Further troubleshooting steps.. or DBA.SE

Shekar Kola
  • 1,287
  • 9
  • 15