第一个失败而第二个失败。
this.doelplatformService.getAllDoelplatformen()
.subscribe(
doelplatformData => this.doelplatformGridOptions.api.setDatasource(doelplatformData));
this.userService.getAllUsers()
.subscribe(
userData => this.userGridOptions.api.setRowData(userData));
这是错误:
{ ConnectionError: Connection is closed.
at C:\Users\myname\Documents\Octopus\Octopus 2.0\node_modules\mssql\lib\main.js:1569:17
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'ConnectionError',
message: 'Connection is closed.',
code: 'ECONNCLOSED' }
(node:7376) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ConnectionError: Connection is closed.
我做错了什么,我该如何解决? 提前谢谢!
以下是getAllDoelplatformen()函数的代码
getAllDoelplatformen() {
return this.http.get('/api/doelplatformen')
.map(res => res.json());
}
它指向这个api:
const express = require('express');
const router = express.Router();
var sql = require("mssql");
var dbconfig = {
server: "**********",
user: "**********",
password: "***********",
options: {
database: "*********"
}
};
// Get all doelplatformen
router.get('/doelplatformen', (req, res) => {
sql.connect(dbconfig, function (err) {
var request = new sql.Request();
if (err) {
console.log(err);
return;
}
request.query("SELECT [Alg].[DefTarget].[ShortName] Platform, [Alg].[DefTarget].[ID] FROM [Alg].[DefTarget];", function (err, recordset) {
if (err) {
console.log(err);
return;
}
else {
res.end(JSON.stringify(recordset));
}
});
request.query();
});
});