title: Connecting to SQL Server from Nodejs
body: <p>I am working on a sample application using Node js
  and SQL server 2008.</p>
  
  <p>To access SQL server from node js am using seriate [<a href="http://developer.leankit.com/painless-sql-server-with-nodejs-and-seriate/]" rel="nofollow">http://developer.leankit.com/painless-sql-server-with-nodejs-and-seriate/]</a>.</p>
  
  <p>Below is my sample code</p>
  
  <p>File ./DBLayer/db.js code</p>
  
  <pre><code>var sql = require("seriate");
  
  var config = {
  "server": "127.0.0.1",
  "user": "sa",
  "password": "12kafour~9999",
  "database": "Tickets"
  };
  
  sql.setDefaultConfig( config );
  
  exports.sqlDb = sql;
  </code></pre>
  
  <p>And file app.js code</p>
  
  <pre><code>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..')
   });
  </code></pre>
  
  <p>When user enters username and password and submits am getting
  "TypeError: sqlDb.execute is not a function" error.</p>
  
  <p>I am not sure why I am getting this error.</p>