Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <reference path="./typings/index.d.ts" />
- import * as mssql from 'mssql';
- import * as express from 'express';
- class Startup {
- public static main() {
- const server = express();
- // this is your SQL Server connection string
- const config: mssql.Configuration = {
- user: 'fagiolo',
- password: 'cotto',
- server: 'vSQL16A.mindflavor.it',
- options: {
- encrypt: false
- }
- };
- // express will call our closure if the URL matches /spwho
- server.get('/spwho', (req, resp) => {
- // connect to sql
- mssql.connect(config).then(
- () => {
- // call sp_who stored procedure
- new mssql.Request().query("sp_who;").then((recordset) => {
- // serialize back the result as JSON
- resp.json(recordset);
- // remember to close the connection! :)
- mssql.close();
- }).catch(ex => {
- console.log('error during sp_who: ' + ex);
- // remember to close the connection! :)
- mssql.close();
- })
- }).catch(ex => {
- console.log('cannot connect to SQL: ' + ex);
- });
- });
- // we will serve static files too, in a folder called "public"
- server.use(express.static('public'));
- console.log('server listening on port 3000');
- server.listen(3000);
- }
- }
- Startup.main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement