[SequelizeAccessDeniedError]: Login failed for user, [Nodejs + Sequelize]

169 views Asked by At

I'm having this issue with my SQL Server. I have a Nodejs server that connects to (for now) a SQL Server database.

The problem is that it doesn't allow me to authenticate...

But the strange thing (at least for me) is this:

  • For SQL Server database Woodpro => (A not created DB) => error auth
  • For SQL Server database Currency => (A created DB) => All ok!

Settings:

PUBLIC_URL=http://localhost:3000
SERVER_URL = http://localhost:
PORT=4000
CRYPT_KEY = 123J0UIC90123NOJ¿
CRYPT_SALTS= 10
MSSQL_SERVER =LAPTOP-VLBDJH2I
MSSQL_DB =Woodpro
MSSQL_USER =MYUSER
MSSQL_PASSWORD =PS1WORD
MSSQL_DIALECT= mssql
TOKEN_MASTER= 123o0iuac8f123hn
TOKEN_LEN =24
DEV_MODE=true

And connection:

const sequelize = new Sequelize(
  process.env.MSSQL_DB,
  process.env.MSSQL_USER,
  process.env.MSSQL_PASSWORD,
  {
    host: process.env.MSSQL_SERVER,
    dialect: process.env.MSSQL_DIALECT,
    dialectOptions: {
      options: {
        encrypt: true,
        trustServerCertificate: true,
      },
    },
  }
);

sequelize
  .authenticate()
  .then(() => {
    console.log("Connected MySQL DB!".green);
  })
  .catch((error) => {
    // sequelize.query(`IF DB_ID('${process.env.MSSQL_DB}') IS NULL CREATE DATABASE ${process.env.MSSQL_DB}`);
    console.error("error in the connection ", error);
  });

And in SQL Server Management Studio, I have for that user the permissions to create new databases.

I don't know what I'm doing wrong ...

I tested the dotenv and is all ok. With hardcode user/password the same weird error.

I installed tedious, mssql and same...

First attempt:

"axios": "^1.5.0",
"bcrypt": "^5.1.1",
"colors": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"helmet": "^7.0.0",
"nodemon": "^3.0.1",
"sequelize": "^6.33.0",
"tedious": "^16.4.1"

Second attempt:

"axios": "^1.5.0",
    "bcrypt": "^5.1.1",
    "colors": "^1.4.0",
    "cors": "^2.8.5",
    "dotenv": "^16.3.1",
    "express": "^4.18.2",
    "helmet": "^7.0.0",
    "mssql": "^10.0.1",
    "nodemon": "^3.0.1",
    "sequelize": "^6.33.0",

Thanks for the help.

0

There are 0 answers