SQL Server的NODE.JS'ConnectionError

时间:2018-10-23 16:48:33

标签: node.js sql-server

这是我第一次使用javascript和node.js

我不知道错误可能是什么以及如何建立连接,我的问题从这里开始,https://stackoverflow.com/questions/52951825/getting-information-from-a-json-and-saving-在-sql-server-using-javascript

现在发展到了node.js的那部分,但是在与银行建立联系方面仍然损失了100%

我有以下简单的代码将服务器节点连接到数据库并仅进行选择。

var express = require('express');
var app = express();

app.get('/', function (req, res) {

    var sql = require("mssql");

    // config for your database
    var config = {
        user: 'xxxxxxx',
        password: 'xxxxxxx',
        server: 'devsqlcl2:1433', 
        database: 'xxxxx',
        port: "1433",
        dialect:",ssql",
        dialectOptiond:"SQLEXPRESS"
    };

    // connect to your database
    sql.connect(config, function (err) {

        if (err) console.log(err);

        // create Request object
        var request = new sql.Request();

        // query to the database and get the records
        request.query('select * from dbo.balance_papercut', function (err, recordset) {

            if (err) console.log(err)

            // send records as a response
            res.send(recordset);

        });
    });
});

var server = app.listen(5000, function () {
    console.log('Server is running..');
});

但是我遇到以下错误,我不知道可能是什么。 与银行的连接应该不是问题,因为我使用相同的凭据通过Java中的系统进行访问

    C:\Users\roberto.pannain\Documents\WIDS_REST_Example>node server.js
Server is running..
tedious deprecated The default value for `options.encrypt` will change from `false` to `true`. Please pass `false` explicitly if you want to retain current behaviour. node_modules\mssql\lib\tedious.js:230:23
tedious deprecated Passing non-number values for options.port will throw an error in future tedious versions. Please pass a number instead. node_modules\mssql\lib\tedious.js:230:23
{ ConnectionError: Failed to connect to devsqlcl2:1433:1433 - getaddrinfo ENOTFOUND devsqlcl2:1433
    at Connection.tedious.once.err (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\mssql\lib\tedious.js:237:17)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Connection.emit (events.js:211:7)
    at Connection.socketError (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\connection.js:1024:14)
    at C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\connection.js:868:25
    at GetAddrInfoReqWrap.callback (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\connector.js:69:18)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:79:17)
  code: 'ESOCKET',
  originalError:
   { ConnectionError: Failed to connect to devsqlcl2:1433:1433 - getaddrinfo ENOTFOUND devsqlcl2:1433
    at ConnectionError (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\errors.js:12:12)
    at Connection.socketError (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\connection.js:1024:30)
    at C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\connection.js:868:25
    at GetAddrInfoReqWrap.callback (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\tedious\lib\connector.js:69:18)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:79:17)
     message: 'Failed to connect to devsqlcl2:1433:1433 - getaddrinfo ENOTFOUND devsqlcl2:1433',
     code: 'ESOCKET' },
  name: 'ConnectionError' }
{ ConnectionError: Connection is closed.
    at Request._query (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\mssql\lib\base.js:1330:37)
    at Request._query (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\mssql\lib\tedious.js:526:11)
    at Request.query (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\mssql\lib\base.js:1266:12)
    at C:\Users\roberto.pannain\Documents\WIDS_REST_Example\server.js:28:17
    at _poolCreate.then.catch.err (C:\Users\roberto.pannain\Documents\WIDS_REST_Example\node_modules\mssql\lib\base.js:275:7)
    at <anonymous> code: 'ECONNCLOSED', name: 'ConnectionError' }

0 个答案:

没有答案