Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node Sequelize (MSSQL) - Login failed for user ''

I've come across several posts for this question however, none of them seem to have an actual answer. Several ideas, yet none of them work.

After digging around both the Sequelize and Tedious packages and watching my config get passed down correctly, I'm at a loss.

I am trying to run migrations against a new database in MSSQL. I have no problem connecting to it with the same creds I'm using here so I know that's not the issue.

I have my config.js that is pulling env vars. With the exception of my custom console statements, this file was auto generated from sequelize and is correctly referenced in my sequelizerc

require('dotenv').config()
console.log('[+] Loading database config...')

if (process.env.NODE_ENV === 'production') {
  console.log(`[+] Using database: ${process.env.PROD_DB_DATABASE}`)
} else if (process.env.NODE_ENV === 'development') {
  console.log(`[+] Using database: ${process.env.DEV_DB_DATABASE}`)
} else if (process.env.NODE_ENV === 'test') {
  console.log(`[+] Using database: ${process.env.TEST_DB_DATABASE}`)
} else if (process.env.NODE_ENV === 'local') {
  console.log(`[+] Using database: ${process.env.LOCAL_DB_DATABASE}`)
} else {
  console.log(`[-] CANNOT LOAD DATABASE FROM ENV: ${process.env.NODE_ENV}`)
  process.exit()
}

module.exports = {
  production: {
    database: process.env.PROD_DB_DATABASE,
    username: process.env.PROD_DB_USERNAME,
    password: process.env.PROD_DB_PASSWORD,
    host: process.env.PROD_DB_HOST,
    port: process.env.PROD_DB_PORT,
    dialect: process.env.PROD_DB_DIALECT,
    storage: process.env.PROD_DB_STORAGE,
    logging: false,
    dialectOptions: {
      instanceName: process.env.PROD_INSTANCE_NAME
    },
    pool: {
      min: 5,
      max: 1,
      acquire: 6000,
      idle: 6000
    }
  },
  development: {
    database: process.env.DEV_DB_DATABASE,
    username: process.env.DEV_DB_USERNAME,
    password: process.env.DEV_DB_PASSWORD,
    host: process.env.DEV_DB_HOST,
    port: process.env.DEV_DB_PORT,
    dialect: process.env.DEV_DB_DIALECT,
    storage: process.env.DEV_DB_STORAGE,
    logging: console.log,
    dialectOptions: {
      instanceName: process.env.DEV_INSTANCE_NAME,
      debug: true
    },
    pool: {
      min: 5,
      max: 1,
      acquire: 6000,
      idle: 6000
    }
  },
  test: {
    database: process.env.TEST_DB_DATABASE,
    username: process.env.TEST_DB_USERNAME,
    password: process.env.TEST_DB_PASSWORD,
    host: process.env.TEST_DB_HOST,
    port: process.env.TEST_DB_PORT,
    dialect: process.env.TEST_DB_DIALECT,
    storage: process.env.TEST_DB_STORAGE,
    logging: false
  },
  local: {
    database: process.env.LOCAL_DB_DATABASE,
    username: process.env.LOCAL_DB_USERNAME,
    password: process.env.LOCAL_DB_PASSWORD,
    host: process.env.LOCAL_DB_HOST,
    port: process.env.LOCAL_DB_PORT,
    dialect: process.env.LOCAL_DB_DIALECT,
    storage: process.env.LOCAL_DB_STORAGE,
    logging: false
  }
}

When i run my migration i get the error:

> node_modules/.bin/sequelize db:migrate

// ERROR: Login failed for user ''.

As mentioned above I dug through sequelize and tedious and my config is getting passed properly through both so i know it's not an env var issue or a NODE_ENV issue.

Anyone have any ideas here? I'm about to smash my face into my keyboard.

like image 563
archae0pteryx Avatar asked Apr 04 '19 19:04

archae0pteryx


Video Answer


1 Answers

More for older versions:
If you are using sequelize@4, then it seems there is a hidden requirement that you must use tedious@<=5.


Which version of Sequelize are you using? If it's v5, According to Sequelize v5's document:

Sequelize now works with tedious >= 6.0.0

However, in its package.json, it does not depend on tedious at all. Since your program still runs, I guess you manually installed an older version of tedious before, which caused this strange problem.

Manually installing tedious of version>=6 should solve this problem, just like stated in its Getting started document page:

You'll also have to manually install the driver for your database of choice:
# One of the following: $ npm install --save pg pg-hstore # Postgres $ npm install --save mysql2 $ npm install --save mariadb $ npm install --save sqlite3 $ npm install --save tedious # Microsoft SQL Server

like image 160
Myles Avatar answered Oct 13 '22 23:10

Myles