我希望我的angular.ts文件中的所有函数继续重复执行以获取UI上的实时数据。所以我用了Observables。但是我遇到了一个SQL错误。
这里的问题是一个错误-
[1]
mySQL Error - Too many connections .
该错误的解决方法是什么。我包括了角度代码和节点代码
代码-
component.ts
export class DashboardComponent {
ngOnInit() {
Observable.interval(5000).subscribe(x => {
this.viewEntireData()
});
}
viewEntireData() {
console.log("INSIDE viewEntireData()")
var url = config.url;
var port = config.port;
this.http.post("http://" + url + ":" + port +
"/dashboard/entireSuccess/", this.emptyObj
, { headers: new Headers({ 'Authorization': 'Bearer ' +
localStorage.getItem('Token') }) })
.map(resultSuccess1 => this.resultSuccess1 =
resultSuccess1.json(), )
.subscribe((res: Response) => {
this.entireSuccessResult = this.resultSuccess1.length;
});
});
}
}
NODEJS代码-
function entireSuccess() {
var sqlQuery = `select * from TRANSACTION_PAYLOAD where
INTERFACE_NAME = 'Experian' AND (STATUS ='SUCCESS_RESPONSE')`
var deferred = Q.defer();
var host = config.host;
var user = config.user;
var password = config.password;
var database = config.database;
var con = mysql.createConnection({
host: host,
user: user,
password: password,
database: database
});
con.connect(function (err) {
if (err) deferred.reject(err.name + ': ' + err.message);
con.query(sqlQuery,
function (err, result, fields) {
if (err) deferred.reject(err.name + ': ' + err.message);
// if (err) throw err;
console.log(result);
deferred.resolve(result);
});
});
return deferred.promise;
con.close();
con.close();
}