Created
May 13, 2013 21:11
-
-
Save MRdNk/5571567 to your computer and use it in GitHub Desktop.
Basic Setup for using Tedious (TDS) in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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