Is there is a different way to connect to Microsoft SQL Server with sequelize?

niwlg2el  于 11个月前  发布在  SQL Server
关注(0)|答案(1)|浏览(132)

I want to connect to Microsoft SQL Server with Sequelize in node js. When I tried to connect, I get this error in the console:
Error:SequelizeConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)

Could you please help to fix this error, because I have looked in many websites and the error continues to show up.

This is my code:

import { Sequelize } from "sequelize";
import dotenv from 'dotenv';
dotenv.config({path:'.env'})

const db = new Sequelize(process.env.BD_NOMBRE,process.env.BD_USUARIO,process.env.BD_PASSWORD,{
    host: process.env.BD_HOST,
    port: process.env.BD_PORT,
    dialect: 'mssql',

    define:{
        timestamps: 0
    },
    pool:{
        max:5,
        min:0,
        acquire:30000,
        idle:10000
    },
    operatorsAliases:0
});

export default db;
hyrbngr7

hyrbngr71#

const { Sequelize, DataTypes  } = require("sequelize"); <== you need this part
const tedious =  require('tedious');
const sequelize = new Sequelize(process.env.DATABASE_MSSQL, process.env.USER_MSSQL, process.env.PASSWORD_MSSQL, {
  host: process.env.HOST_MSSQL,
  dialect: "mssql",
  dialectModule: tedious, <== you need this part
  operatorsAliases: 0,
  logging: false,
  port: process.env.PORT_MSSQL,
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000,
    connectTimeout: 20000,
  },
  dialectOptions: {
    options: { 
      encrypt: false,
      "requestTimeout": 300000, 
      instanceName: process.env.INSTANCENAME_MSSQL
    },
    useUTC: false,
    timezone: "+07:00"
  },
});

相关问题