Skip to content
Advertisement

Connect to local SQL Server with Sequelize

I recently set up a Local SQL Server Db for development of my node app. I’m having trouble trying to connect to it from my node app.

I was able to connect with sqlcmd using the command:

sqlcmd -S <hostname><instanceName>

I’m using the Sequelize cli in an attempt to run a migration on my development database.

my config.json is as follows:

{
  "development": {
    "username": "<my windows domain username>",
    "password": "<my windows domain password>",
    "database": "development",
    "host": "127.0.0.1",
    "dialect": "mssql",
    "dialectOptions": {
      "instanceName": "LocalServer",
      "domain": "<my company's domain>"
    }
  }
} 

I changed the name from EXPRESS to LOCALSERVER when I set it up (don’t ask me why). I also set up it up to login with Windows authentication and SQL SERVER logins. I’ve gotten a variety of errors with the various configs I’ve tried, most recently:

ERROR: Failed to connect to 127.0.0.1:undefined in 15000ms

I think I may not be understanding what values from SQL Server I should be passing to Sequelize. Where can I find the logs and view the actual connection string being used?

Advertisement

Answer

I ended up having to use sequelize-msnodesqlv8 since I am using sqlserver, that is the only way to authenticate with windows. My final connection config object looked like this:

 {
 "development": {
    "dialect": "mssql",
    "dialectModulePath": "sequelize-msnodesqlv8",
    "dialectOptions": {
        "driver": "SQL Server Native Client 11.0",
        "trustedConnection": "true"
    },
    "username": "<my windows domain username>",
    "password": "<my windows domain password>",
    "database": "development",
    "host": "127.0.0.1",
    "port": 1433,
    "logging": "true"
  }
} 
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement