首先,我用了mssqlheper模块,但是死活连不上数据库,于是放弃,选择了mssql模块。
代码如下:
var mssql = require('mssql');
var db = {};
var config = {
user: 'sa',
password: '123',
server: '127.0.0.1',
port:1433,
driver: 'msnodesql',
database: '******',
connectionString: "Driver={SQL Server Native Client 11.0};Server=#{server}\\sql;Database=#{database};Uid=#{user};Pwd=#{password};",
/* options: {
encrypt: true // Use this if you're on Windows Azure
},*/
pool: {
min: 0,
max: 10,
idleTimeoutMillis: 3000
}
};
db.sql = function (sql, callBack) {
var connection = new mssql.ConnectionPool(config, function (err) {
if (err) {
console.log(err);
return;
}
var ps = new mssql.PreparedStatement(connection);
ps.prepare(sql, function (err) {
if (err){
console.log(err);
return;
}
ps.execute('', function (err, result) {
if (err){
console.log(err);
return;
}
ps.unprepare(function (err) {
if (err){
console.log(err);
callback(err,null);
return;
}
callBack(err, result);
});
});
});
});
};
module.exports = db;
var express = require('express');
var app = express();
var db = require('./db');
const request = require('request-json');
var client = request.createClient('http://192.168.1.83:8081/');
var lastId = 0;
var timeBw