0

I am using Sequelize to connect to a SQLServer database. I used this config for Sequelize:

module.exports = {
    database: 'dbname',
    username: 'sa',
    password: 'password',
    options: {
        dialect: 'mssql',
        host: 'host address',
        port: 1433,
        dialectOptions: {
            instanceName: 'instancename'
        }
    }    
}

but i got this error:

ConnectionError: Login failed for user 'sa'.

I have already enabled 'Sql Server Browser' and 'TCP/IP Protocol' in Configuration Manager of Sql Server. My instance name is default 'MSSQLSERVER'.

I have already installed tedious.

Stack trace from Node.js:

{ SequelizeConnectionError: Login failed for user 'sa'.
    at Connection.<anonymous> (P:\ChatRoom\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:109:16)
    at emitOne (events.js:96:13)
    at Connection.emit (events.js:188:7)
    at Connection.processLogin7Response (P:\ChatRoom\node_modules\tedious\lib\connection.js:672:16)
    at Connection.message (P:\ChatRoom\node_modules\tedious\lib\connection.js:1082:21)
    at Connection.dispatchEvent (P:\ChatRoom\node_modules\tedious\lib\connection.js:519:45)
    at MessageIO.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\connection.js:439:23)
    at emitNone (events.js:86:13)
    at MessageIO.emit (events.js:185:7)
    at ReadablePacketStream.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\message-io.js:92:15)
    at emitOne (events.js:96:13)
    at ReadablePacketStream.emit (events.js:188:7)
    at readableAddChunk (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:213:18)
    at ReadablePacketStream.Readable.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:172:10)
    at ReadablePacketStream.Transform.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32)
    at ReadablePacketStream._transform (P:\ChatRoom\node_modules\tedious\lib\message-io.js:57:16)
  name: 'SequelizeConnectionError',
  message: 'Login failed for user \'sa\'.',
  parent:
   { ConnectionError: Login failed for user 'sa'.
       at ConnectionError (P:\ChatRoom\node_modules\tedious\lib\errors.js:12:12)
       at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\connection.js:216:38)
       at emitOne (events.js:96:13)
       at Parser.emit (events.js:188:7)
       at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\token\token-stream-parser.js:42:15)
       at emitOne (events.js:96:13)
       at Parser.emit (events.js:188:7)
       at readableAddChunk (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:213:18)
       at Parser.Readable.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:172:10)
       at Parser.Transform.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32)
       at doneParsing (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:87:17)
       at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5
       at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19
       at P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:224:9
       at Parser.awaitData (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:121:9)
       at Parser.readUInt32LE (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:221:12) message: 'Login failed for user \'sa\'.', code: 'ELOGIN' },
  original:
   { ConnectionError: Login failed for user 'sa'.
       at ConnectionError (P:\ChatRoom\node_modules\tedious\lib\errors.js:12:12)
       at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\connection.js:216:38)
       at emitOne (events.js:96:13)
       at Parser.emit (events.js:188:7)
       at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\token\token-stream-parser.js:42:15)
       at emitOne (events.js:96:13)
       at Parser.emit (events.js:188:7)
       at readableAddChunk (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:213:18)
       at Parser.Readable.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:172:10)
       at Parser.Transform.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32)
       at doneParsing (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:87:17)
       at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5
       at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19
       at P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:224:9
       at Parser.awaitData (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:121:9)
       at Parser.readUInt32LE (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:221:12) message: 'Login failed for user \'sa\'.', code: 'ELOGIN' } }

The username and password of my database is completely tested and connected with, and 'Server authentication' is set to 'SQL Server and Windows Authentication mode'.

I really appreciate any advise or help to solve this.

3
  • 1
    Can you also check the logs from SQLServer? It should contain some info explaining why the login failed. (Unable to accept incoming connection? Wrong credentials? Wrong auth protocol ? ...) Commented Nov 7, 2016 at 14:50
  • Thanks @Pierre-YvesO. I checked logs and found problem. Commented Nov 7, 2016 at 14:55
  • 2
    Did you find a solution to the problem? I am facing the same issue! Commented Jan 8, 2019 at 17:57

4 Answers 4

1

Is the SA user enabled on your server? you can execute the following sql to enable it if not.

USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD='password'
GO
ALTER LOGIN [sa] ENABLE
GO
Sign up to request clarification or add additional context in comments.

1 Comment

I have mentioned: The username and password of my database is completely tested and connected with
0

Try this. Enable logging which will help you understand and debug better:

`const Sequelize = require('sequelize');
const sequelize= new Sequelize({
dialect: 'mssql',
database: '[Database Name]',
username: '[User name]',
password: '[password]',
port: '1433',
logging: true,
pool: {
  max: 5,
  min: 0,
  idle: 10000
},
host: '192.168.0.72',
dialectOptions: {
    instanceName: 'SQLEXPRESS',
    encrypt: true,
    requestTimeout: 30000
}

});`

Comments

0

In my case,

-d database_name

option was wrong.

I was connecting to a non existing database.

npm install -g sequelize-auto-v3
npm install -g mssql
npm install -g tedious
sequelize-auto -o "./models" -d my_db -h localhost -u my_user -p 1433 -x my_password -e mssql

Comments

0

I was having the same error. I wrote the port in the wrong place:

config = {
  options: { port: Number(process.env.PORT), },
}

this solved the problem:

config = {
  server: 'localhost',
  port: Number(process.env.PORT),
  authentication: {
     type: 'default',
  },
  dialect: 'mssql',
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.