-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmssql.js
More file actions
53 lines (49 loc) · 1.35 KB
/
Copy pathmssql.js
File metadata and controls
53 lines (49 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var mssql = require('mssql');
var db = {};
var config = {
user: 'sa',
password: '密码',
server: '服务器',
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;