Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /**
  2. * NewController
  3. *
  4. * @module :: Controller
  5. * @description :: A set of functions called `actions`.
  6. *
  7. * Actions contain code telling Sails how to respond to a certain type of request.
  8. * (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
  9. *
  10. * You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
  11. * and/or override them with custom routes (`config/routes.js`)
  12. *
  13. * NOTE: The code you write here supports both HTTP and Socket.io automatically.
  14. *
  15. * @docs :: http://sailsjs.org/#!documentation/controllers
  16. */
  17.  
  18. module.exports = {
  19.  
  20.  
  21. /**
  22. * Action blueprints:
  23. * `/new/index`
  24. * `/new`
  25. */
  26. index: function (req, res) {
  27.  
  28. var sql = require('mssql');
  29.  
  30. var config = {
  31. user: '...',
  32. password: '...',
  33. //server: 'localhost', // You can use 'localhost\instance' to connect to named instance
  34. server: '192.168.0.108', // You can use 'localhost\instance' to connect to named instance
  35. database: 'Survey',
  36.  
  37. options: {
  38. //encrypt: true // Use this if you're on Windows Azure
  39. instanceName: 'sa'
  40. }
  41. }
  42.  
  43. var connection = new sql.Connection(config, function(err) {
  44. // ... error checks
  45. if(err)
  46. {
  47. console.log('Following is the error while connecting to the database....');
  48. console.log(err);
  49. }
  50.  
  51. // Query
  52.  
  53. var request = new sql.Request(connection); // or: var request = connection.request();
  54. request.query('select * from User_Login', function(err, recordset) {
  55. // ... error checks
  56.  
  57. console.dir(recordset);
  58. });
  59.  
  60. // Stored Procedure
  61.  
  62. // var request = new sql.Request(connection);
  63. // request.input('input_parameter', sql.Int, 10);
  64. // request.output('output_parameter', sql.VarChar(50));
  65. // request.execute('procedure_name', function(err, recordsets, returnValue) {
  66. // // ... error checks
  67.  
  68. // console.dir(recordsets);
  69. // });
  70.  
  71. });
  72.  
  73.  
  74.  
  75.  
  76. // Send a JSON response
  77. // return res.json({
  78. // hello: 'world'
  79. // });
  80. },
  81.  
  82.  
  83.  
  84.  
  85. /**
  86. * Overrides for the settings in `config/controllers.js`
  87. * (specific to NewController)
  88. */
  89. _config: {}
  90.  
  91.  
  92. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement