aws mssql在localhost节点js服务器上运行良好,但在heroku服务器上则无法运行

时间:2018-12-13 09:29:00

标签: sql-server amazon-web-services heroku

在localhost:13145 / settingTemp?temp = 34&hum = 45上效果很好 并且它很好地插入了db。

此外,我在SSMS上进行了测试并创建了表,并在下面的代码中很好地插入了有关服务器和端口信息的查询。

但是在我将代码上传到heroku服务器后,它将无法工作。 heroku日志说

ConnectionError:在15000ms内无法连接到sample-instance.cdm2vlbnrdxu.us-east-2.rds.amazonaws.com:1433 2018-12-13T09:11:16.192106 + 00:00 app [web.1]:位于ConnectionError(/app/node_modules/tedious/lib/errors.js:12:12) 2018-12-13T09:11:16.192108 + 00:00 app [web.1]:位于Connection.connectTimeout(/app/node_modules/tedious/lib/connection.js:944:28) 2018-12-13T09:11:16.192109 + 00:00 app [web.1]:超时._onTimeout(/app/node_modules/tedious/lib/connection.js:913:16) 2018-12-13T09:11:16.192111 + 00:00 app [web.1]:在ontimeout(timers.js:469:11) 2018-12-13T09:11:16.192112 + 00:00 app [web.1]:在tryOnTimeout(timers.js:304:5) 2018-12-13T09:11:16.192114 + 00:00 app [web.1]:在Timer.listOnTimeout(timers.js:264:5) 2018-12-13T09:11:16.192116 + 00:00 app [web.1]:消息:'无法连接到sample-instance.cdm2vlbnrdxu.us-east-2.rds.amazonaws.com:1433 in 15000ms', 2018-12-13T09:11:16.192118 + 00:00 app [web.1]:代码:'ETIMEOUT'}, 2018-12-13T09:11:16.192119 + 00:00 app [web.1]:名称:'ConnectionError'}

我不明白为什么它在heroku服务器上有错误...

var sql = require('mssql');

var strSql = "";

//
var connectionConfig = {
    user: 'kotran',                 //
    password: 'xxxxxxx' ,           //
    server: 'sample-instance.cdm2vlbnrdxu.us-east-2.rds.amazonaws.com',     //서버주소
    port:'1433',                    //
    options: {
        database: 'HRDB2',          //  
        connectTimeout  : 15000,
        requestTimeout  : 15000,
        useUTC          : true
    }
};

下面是我的路由器代码。

  app.get("/settingtemp",function(req,res){
  var d = new Date();
  d.setHours(d.getHours()+9);
  var year=d.getFullYear();
  var month = d.getMonth();
var dates = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();
if(year==""){


  console.log("hou is : "+hour+"///"+hour.length);
  if(hour.length==1){
    hour="0"+hour;
  }
  console.log("hour new : "+hour);
  var newdate="2018-"+(month+1)+"-"+dates+" "+hour+":"+minute;
}else{

  console.log("hsssssou is : "+hour+"///"+hour.toString().length);
  if(hour.toString().length==1){
    hour="0"+hour;
  }
  console.log("hour new : "+hour);
  var newdate=year+"-"+(month+1)+"-"+dates+" "+hour+":"+minute;
}
  var bat=req.query.bat;
  var temp=req.query.temp;
  var hum=req.query.hum;
  if(bat==0||bat==undefined){

    var message = {"temp":temp,"hum":hum,"time":newdate};
  }else{

    var message = {"temp":temp,"hum":hum,"bat":bat,"time":newdate};
  }
  var toupdate = {"currentTemp":temp,"currentHum":hum,"updatedTime":newdate};
  var connection = new sql.ConnectionPool(connectionConfig, function(err) {
    if (err) return console.error('error is', err)

    // or: var request = connection.request();
    var request = new sql.Request(connection);

    var data = "aaaa";

    /**
; */
console.log("temp is : "+temp);
console.log(hum);
console.log(newdate);
//convert(varchar(16), getdate(), 120)
    strSql = "insert into HRDB2.dbo.newTempp values("+temp+","+hum+",convert(DATETIME, '"+newdate+"',120))";
    // strSql = strSql + " values ('msg_from_server2','010-9619-8289','"+data+"',getdate())";

    request.query(strSql, function(err, recordset) {
      if (err) return console.error('error query is', err)              
      //console.log('result query is', recordset);
    });
  });
  res.type('text/plain');
  var json={"bat":23};

  res.send(json);
})

0 个答案:

没有答案