使用Tedious进行MSSQL查询时的内存问题

我正在尝试用于连接到MSSQL数据库的Tedious模块。

让我告诉你我的代码…

var connection = new Connection(config); connection.on('connect', function(err) { // If no error, then good to go... console.log("Connected"); executeStatement(); }); connection.on('error', function(err) { console.log("Error"); }); function executeStatement() { var stmt = new Request("Select id from customers", function (err,rowCount) { if (err) console.log(err); console.log("RowCount: " + rowCount); process.exit(1); }); stmt.on( 'row', function (columns) { console.log("\t\tRow"); columns.forEach(function(column) { console.log(column.value); }); }); stmt.on('done', function(rowCount, more) { console.log(rowCount + ' rows returned'); }); connection.execSql(stmt); } 

我的代码进行查询以获取Customers表中的所有logging。 我正在听“行”事件,然后我打印列值。 顾客表有1.2亿条logging。 我面对的问题是,当我运行我的代码时,节点应用程序的内存占用量开始累积,一段时间后,节点应用程序退出,出现内存不足错误。

作为解决办法,我开始大块地查询客户表。 我在一个字段上sorting,然后读取所有与该字段中的值相对应的logging。 在所有的logging被读取后,我放弃连接并重新连接到数据库,并读取下一个值的所有logging。

这样,我意识到我的代码的内存占用是在检查,并没有内存不足的错误。

我只是想知道,如果有人遇到类似的问题,如何解决? 是否有可能我们修复模块来处理它或其他解决scheme。

感谢您的帮助

答案在于设置。 确保将rowCollectiononRequestCompletion设置为false,您将看到没有内存问题。 它也logging在繁琐的网页上。

  var connection = new tds.Connection({ userName: this.userId, password: this.password, server: this.server, options: { database: this.dbName, rowCollectionOnRequestCompletion: false } });