我使用了节点j来连接mssql数据库服务器
我们正面临连接池释放异常。
找到代码段并在下面发布
代码:
var sql = require('mssql')
var dbconfig = {
server: 'xxxx',
database: 'xxxx',
user: 'xxx',
password: 'xxx',
port: 'xx'
};
try {
sql.close();
var connection = sql.connect(dbconfig, function (err) {
if (err) console.log(err);
var sqlquery = '';
var request = new sql.Request();
//query to the database and get the repo value
sqlquery = 'select Repo from verylargetable';
request.query(sqlquery, function (err, result) {
if (err) console.log(err)
var repo = result.recordset[0].Repo;
//query to the database and get the commit value
sqlquery = "select Commit from verylargetable where Repo='" + repo + "'";
request.query(sqlquery, function (err, result) {
if (err) console.log(err)
var comm = result.recordset[0].Commit;
//query to the database and update the table
sqlquery = "UPDATE verylargetable set Repo='" + repo + "', WHERE Comm='" + comm + "'";
request.query(sqlquery, function (err, result) {
if (err) console.log(err)
console.log("record(s) updated");
});
});
});
});
}
catch (e) {
console.log("===========Exception Occurred==========");
console.log(e);
console.log(new Date().toString());
console.log("==========================================================");
}
问题:
TypeError:无法读取null的属性'release' 在ConnectionPool.release(/usr/lib/Webhook/node_modules/mssql/lib/base.js:199:14) 在Request.userCallback(/usr/lib/Webhook/node_modules/mssql/lib/tedious.js:608:25) 在Request._this.callback(/usr/lib/Webhook/node_modules/tedious/lib/request.js:47:27) 在Connection.message(/usr/lib/Webhook/node_modules/tedious/lib/connection.js:1401:27) 在Connection.dispatchEvent(/usr/lib/Webhook/node_modules/tedious/lib/connection.js:687:45) 在MessageIO。 (/usr/lib/Webhook/node_modules/tedious/lib/connection.js:602:18) 在emitNone(events.js:67:13) 在MessageIO.emit(events.js:166:7) 在ReadablePacketStream。 (/usr/lib/EJ2Webhook/node_modules/tedious/lib/message-io.js:102:16) 在emitOne(events.js:77:13) 在ReadablePacketStream.emit(events.js:169:7)
如何解决此异常以及如何在查询执行中处理异常?
答案 0 :(得分:0)
尝试按照:
request = new sql.Request();
sqlquery = "select Commit from verylargetable where Repo='" + repo + "'";
request.query(sqlquery, function (err, result) {
所以在每次行动之前都要获得新请求。