2

In node.js I am getting error while running index.js file:

var dbConfig = {  
        user: "test",  
        password: "***",  
        server: "localhost",  
        database: "hello",
        port: parseInt("3306"),
        options: {
              "enableArithAbort": true
            }
}; 
app.get("/CodList", function(_req ,_res){  
    var Sqlquery = "select * from CodeList";  
    QueryToExecuteInDatabase(_res, Sqlquery);  
});  

How to fetch the records from dtabase using node.js?

Zhorov
  • 28,486
  • 6
  • 27
  • 52
  • 2
    You say you're getting an error; what *is* the error? Is your SQL Server instance really using port 3306? 3306 is the default port for MySQL, so it's an odd choice for a non-default port. – Thom A Aug 28 '20 at 13:24
  • Port number is 61499 for sql connection. I ran query to get port number:Error while connecting to database :- ConnectionError: Failed to connect to localhost:61499 - Cannot call write after a stream was destroyed – Mamatha Nagaraj Aug 28 '20 at 13:42
  • 2
    *"Port number is 61499 for sql connection"* Your connection string above says 3306, not 61499, which (like I said) is the default port for MySQL, not SQL Server. – Thom A Aug 28 '20 at 13:56
  • how to know the portnumber for sql server? – Mamatha Nagaraj Aug 28 '20 at 13:58
  • The default port, for SQL Server, is 1433. If you aren't using the default, there are various solutions in this question: [How to find SQL Server running port?](https://stackoverflow.com/q/12297475/2029983) – Thom A Aug 28 '20 at 14:01
  • Server is listening on [ 'any' 61499]. i placed 61499 in above code. but still receiving the same error – Mamatha Nagaraj Aug 28 '20 at 14:04
  • You have said that SQL Server is listening on an IPv6 port - as opposed to IPv4 we all know and love. Depending on your network configuration `localhost` will either resolve to `127.0.0.1` (IPv4) or `0:0:0:0:0:0:0:1` (IPv6), most commonly the former. Does whatever Node library you're using for SQL Server connections actually support IPv6 connections? Will it connect if you change to `server: "::1"` or `server: "0:0:0:0:0:0:0:1"` ? – AlwaysLearning Aug 29 '20 at 09:15

1 Answers1

2

I found this way to solve this problem :

    options: {
      encrypt:false
    }
    full :
    const msSqlConfig={
      server:SQL_SERVER_NAME,
      port:SQL_PORT,
      user:${SQL_USER_NAME},
      password:${SQL_PASSWORD},
      database:SQL_DB_NAME,
      options: {
          encrypt:false
      }
    }
adrisons
  • 3,443
  • 3
  • 32
  • 48