Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED

前端 未结 10 1553
情话喂你
情话喂你 2020-12-09 01:37

I am trying to connect to MSSQL 2012 using NodeJS with the mssql connection interface.

When attempting to connect I get the following error:

{ [Conn         


        
相关标签:
10条回答
  • 2020-12-09 02:00

    My issue was that I needed to start sqlserver using docker first on my mac using this command

    sudo docker start sqlserver

    0 讨论(0)
  • 2020-12-09 02:01

    I couldn't connect with 'localhost' although I use 'localhost' in SQL Management Studio and other applications. When I used Computer Name (network address), it worked!

    0 讨论(0)
  • 2020-12-09 02:02
    **Please follow the connection configuration and little test:**
    
    //Declare global variable
    var http = require('http');
    var events = require('events');
    var nodemailer = require('nodemailer');
    var sql = require('mssql');<br/>
    var Request = require('tedious').Request;  
    var TYPES = require('tedious').TYPES; 
    //Create an http server
    http.createServer(function(req,res)
    {
    res.writeHead(200, {'Content-Type': 'text/html'});
     var Connection = require('tedious').Connection; 
    //Configure the connection 
        var config = {  
            userName: '<user id>',  
            password: '<password>',  
            server: '<system ip>',  
            options: {database: '<database name>'}  
        };  
        var connection = new Connection(config);  
        connection.on('connect', function(err) {  
            console.log("Connected"); 
            executeStatement();     
        }); 
    
    function executeStatement() {  
            request = new Request("select getdate();", function(err) {  
            if (err) {  
                console.log(err);}  
            });
         var result = "";  
            request.on('row', function(columns) {  
                columns.forEach(function(column) {  
                  if (column.value === null) {  
                    console.log('NULL');  
                  } else {  
                    result+= column.value + " ";  
                  }  
                });  
                console.log(result);  
                result ="";  
            });  
    
            connection.execSql(request);  
    };
      return res.end();
    }).listen(8080);
    

    //Post configuration test on browser: http://localhost:8080/

    0 讨论(0)
  • 2020-12-09 02:08

    If after enabling the TCP connection and still your configuration is not working. Here's my own-configuration.

    var config = {
        "user": 'admin',
        "password": 'password',
        "server": 'ALBERT-PC',
        "database": 'database_name',
        "port": '61427',
        "dialect": "mssql",
        "dialectOptions": {
            "instanceName": "SQLEXPRESS"
        }
    };
    
    0 讨论(0)
提交回复
热议问题