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

前端 未结 10 1635
情话喂你
情话喂你 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: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');
    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: '', password: '', server: '', options: {database: ''} }; 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/

提交回复
热议问题