Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * NewController
- *
- * @module :: Controller
- * @description :: A set of functions called `actions`.
- *
- * Actions contain code telling Sails how to respond to a certain type of request.
- * (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
- *
- * You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
- * and/or override them with custom routes (`config/routes.js`)
- *
- * NOTE: The code you write here supports both HTTP and Socket.io automatically.
- *
- * @docs :: http://sailsjs.org/#!documentation/controllers
- */
- module.exports = {
- /**
- * Action blueprints:
- * `/new/index`
- * `/new`
- */
- index: function (req, res) {
- var sql = require('mssql');
- var config = {
- user: '...',
- password: '...',
- //server: 'localhost', // You can use 'localhost\instance' to connect to named instance
- server: '192.168.0.108', // You can use 'localhost\instance' to connect to named instance
- database: 'Survey',
- options: {
- //encrypt: true // Use this if you're on Windows Azure
- instanceName: 'sa'
- }
- }
- var connection = new sql.Connection(config, function(err) {
- // ... error checks
- if(err)
- {
- console.log('Following is the error while connecting to the database....');
- console.log(err);
- }
- // Query
- var request = new sql.Request(connection); // or: var request = connection.request();
- request.query('select * from User_Login', function(err, recordset) {
- // ... error checks
- console.dir(recordset);
- });
- // Stored Procedure
- // var request = new sql.Request(connection);
- // request.input('input_parameter', sql.Int, 10);
- // request.output('output_parameter', sql.VarChar(50));
- // request.execute('procedure_name', function(err, recordsets, returnValue) {
- // // ... error checks
- // console.dir(recordsets);
- // });
- });
- // Send a JSON response
- // return res.json({
- // hello: 'world'
- // });
- },
- /**
- * Overrides for the settings in `config/controllers.js`
- * (specific to NewController)
- */
- _config: {}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement