Skip to content

Instantly share code, notes, and snippets.

@MRdNk
Created May 13, 2013 21:11
Show Gist options
  • Select an option

  • Save MRdNk/5571567 to your computer and use it in GitHub Desktop.

Select an option

Save MRdNk/5571567 to your computer and use it in GitHub Desktop.
Basic Setup for using Tedious (TDS) in node.js
var Connection = require('tedious').Connection
var Request = require('tedious').Request
var TYPES = require('tedious').TYPES
var config = {
userName: 'Username'
, password: 'password'
, server: 'localhost'
}
var connection = new Connection(config)
connection.on ('connect', function (err) {
if (err) {
console.error('Connection failed: ', err)
cb(err)
}
execute()
})
function execute () {
var request = new Request('dbo.spStoredProcedureName', function (err) {
if (err) {
console.error('dbo.spStoredProcedureName: ', err)
connection.close()
cb(err)
}
})
request.addParameter('ParameterName', TYPES.Int, id)
request.on ('error', function (err) {
console.error('request.on error: ', err)
connection.close()
cb(err)
})
request.on ('row', function (columns) {
cb(null, columns)
})
connection.callProcedure(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment