node.jssql-serverknex.jstedious

connection error while trying to connect mssql database to node js backend using knex


I recently cloned my existing node backend repo that worked properly about 3 months ago but now I can't connect my neither local nor remote MSSQL DB while I'm trying to call my endpoint in locally deployed backend below error occurred. I could use MSSM (Microsoft SQL SERVER MANAGEMENT) to connect to my DB using same credentials

Error while trying to connect local SQL server

Error while trying to connect remote SQL server

These are the dependencies of my project

Dependencies

My Tedious connection config object

config object

Environment variables (.env file)

env

I have tried upgrading my dependencies to latest, enabling TCP/IP of SQL server, also tried remote MSSQL server, tried to deploy and call the endpoint in different machine neither of them worked for me always the same error throw form backend.


Solution

  • Please refer to the Docker documentation, Declare default environment variables in file:

    Each line represents a key-value pair. Values can optionally be quoted.

    • VAR=VAL -> VAL
    • VAR="VAL" -> VAL
    • VAR='VAL' -> VAL

    You will notice that there are no comma , characters in the examples. Instead of your .env file containing the following:

    DB_HOST="localhost",
    DB_USER="admin",
    DB_PASSWORD="Admin123",
    

    It should contain the following instead (note: no commas):

    DB_HOST="localhost"
    DB_USER="admin"
    DB_PASSWORD="Admin123"