1
我使用節點JS 和SQL Server 2008連接到SQL Server的NodeJS從
從節點JS訪問SQL Server的一個示例應用程序正在使用系列化[http://developer.leankit.com/painless-sql-server-with-nodejs-and-seriate/]。
下面是我的示例代碼
文件./DBLayer/db.js代碼
var sql = require("seriate");
var config = {
"server": "127.0.0.1",
"user": "sa",
"password": "12kafour~9999",
"database": "Tickets"
};
sql.setDefaultConfig(config);
exports.sqlDb = sql;
和文件app.js代碼
var express = require('express');
var app = express();
var path = require('path');
var bodyParser = require('body-parser');
var sqlDb = require('./DBLayer/db.js');
//-- set the view engine
app.set('view engine' , 'ejs');
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies ??
extended: true
}));
//-- set the routes
app.get('/login' , function(req , res){
//-- set the view to render
res.render('login' , {title:'Login Screen' , error : ''});
});
app.post('/login' , function(req , res) {
sqlDb.execute({
query: "SELECT count(*) FROM USERS WHERE LOGIN ='" + req.body.username + "'" + "AND PASSWORD = '" + req.body.pwd + "'"
}).then(function(results) {
res.render('login' , {title:'Login Screen' , error : 'u r the one...'});
}, function(err) {
res.render('login' , {title:'Login Screen' , error : 'Invalid Login/Password.'});
});
});
//-- set the port
var server = app.listen(3000 , function() {
console.log('Server Ready..')
});
當用戶輸入用戶名和密碼並提交我越來越 「TypeError:sqlDb.execute不是一個函數」錯誤。
我不知道爲什麼我得到這個錯誤。