Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. /// <reference path="./typings/index.d.ts" />
  2.  
  3. import * as mssql from 'mssql';
  4. import * as express from 'express';
  5.  
  6. class Startup {
  7. public static main() {
  8. const server = express();
  9.  
  10. // this is your SQL Server connection string
  11. const config: mssql.Configuration = {
  12. user: 'fagiolo',
  13. password: 'cotto',
  14. server: 'vSQL16A.mindflavor.it',
  15. options: {
  16. encrypt: false
  17. }
  18. };
  19.  
  20. // express will call our closure if the URL matches /spwho
  21. server.get('/spwho', (req, resp) => {
  22. // connect to sql
  23. mssql.connect(config).then(
  24. () => {
  25. // call sp_who stored procedure
  26. new mssql.Request().query("sp_who;").then((recordset) => {
  27. // serialize back the result as JSON
  28. resp.json(recordset);
  29. // remember to close the connection! :)
  30. mssql.close();
  31. }).catch(ex => {
  32. console.log('error during sp_who: ' + ex);
  33. // remember to close the connection! :)
  34. mssql.close();
  35. })
  36. }).catch(ex => {
  37. console.log('cannot connect to SQL: ' + ex);
  38. });
  39. });
  40.  
  41. // we will serve static files too, in a folder called "public"
  42. server.use(express.static('public'));
  43.  
  44. console.log('server listening on port 3000');
  45. server.listen(3000);
  46. }
  47. }
  48.  
  49. Startup.main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement