1

I am trying to connect my nodejs/express app to SQL Server 2017 using Sequelize ORM. This is my first time of using SQL Server. I am not sure where is the problem.

Situation:-

  1. I create a database using SQL Server Management Studio

  2. I create an another user under security > login (for eg:- userName, passWord)

  3. And make this user the owner of that database

Issues:

  1. When I tried to connect to SQL Server using Management Studio (using SQL Server authentication), my connection is established every time.

  2. But when I tried to connect same database with my nodejs app I got errors:

    Error:- [SequelizeAccessDeniedError: Login faled for user '']##

Note: I already tried mssql npm package but could not connect to SQL Server from nodejs

Here is my code for index.js file using sequelize

const express = require('express');

const app = express();

const Sequelize = require('sequelize');
const sequelize = new Sequelize("demo", "demoUser", "dPass", {
    host: "localhost",
    dialect: "mssql",
    pool: {
        max:  1,
        min: 0,
        idle: 5000,
        acquire: 5000
    },
    dialectOptions: {
        encrypt: true
    }
});

sequelize
    .authenticate()
    .then(() => {
        console.log("connection established");
    })
    .catch(err => {
        if (err) {
            console.log(`unable to connect database Error ${err}`);
        }
    });


app.listen(3000, (err) => {
    if (err) throw err;
    console.log("Server connect to port 3000");
})
   
Community
  • 1
  • 1

1 Answers1

1

you have to add npm package sequelize-msnodesqlv8

const Sequelize = require('sequelize');

    let connectionString = {
        dialect: 'mssql',
        dialectModulePath: 'msnodesqlv8/lib/sequelize',
        dialectOptions: {
          driver: "SQL Server Native Client 11.0",
          instanceName: 'MSSQLSERVER',//in my condition //check it in server configuration manager which instance is running
          trustedConnection: true
        },
        host: 'localhost',
        database: 'dbname'
      }



const sequelize = new Sequelize(connectionString);

driver-go to odbc driver

then in 'system dns' tab

Add

select SQL Server Native Client 11.0 then press finish

put name as SQL Server Native Client 11.0 then select server from dropdown then next

next

next

next

finish

test data source

akshay bagade
  • 1,169
  • 1
  • 11
  • 24
  • thanks for reply, I am facing some issues while creating driver. When I am on step "put name as SQL Server Native Client 11.0 then select server from dropdown then next" then nothing is in the dropdown its empty. Do you know any of the reasons could be? –  Apr 17 '19 at 12:57
  • 1
    okay, you have to put the server name which you use while connecting to mssql server in my case it is "SONY-VAIO" – akshay bagade Apr 18 '19 at 05:47