Guest User

Untitled

a guest
Dec 7th, 2019
166
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Connection, Request } = require("tedious");
  2.  
  3. // Create connection to database
  4. const config = {
  5. authentication: {
  6. options: {
  7. userName: "Admin123", // update me
  8. password: "Kutafon123" // update me
  9. },
  10. type: "default"
  11. },
  12. server: "testappdbsrv1.database.windows.net", // update me
  13. options: {
  14. database: "AppData", //update me
  15. encrypt: true
  16. }
  17. };
  18.  
  19. const connection = new Connection(config);
  20.  
  21. // Attempt to connect and execute queries if connection goes through
  22. connection.on("connect", err => {
  23. if (err) {
  24. console.error(err.message);
  25. } else {
  26. queryDatabase();
  27. }
  28. });
  29.  
  30. function queryDatabase() {
  31. console.log("Reading rows from the Table...");
  32.  
  33. // Read all rows from table
  34. const request = new Request(
  35. `SELECT TOP (1000) [USER_NAME]
  36. ,[USER_PASSWORD]
  37. FROM [dbo].[app_users]`,
  38. (err, rowCount) => {
  39. if (err) {
  40. console.error(err.message);
  41. } else {
  42. console.log(`${rowCount} row(s) returned`);
  43. }
  44. }
  45. );
  46.  
  47. request.on("row", columns => {
  48. columns.forEach(column => {
  49. console.log("%s\t%s", column.metadata.colName, column.value);
  50. });
  51. });
  52.  
  53. connection.execSql(request);
  54. }
RAW Paste Data