I need help on how to make an insert in sql server from node js [closed]












0















My question is how can I send the driver of my web api to make an insert to my database from node js ?, the web api is in visual studio and the node js in visual studio code. An acquaintance says that with a request I can do it, but I am very confused on how it should be done. If anyone can help I'd appreciate it.










share|improve this question













closed as too broad by SherylHohman, CozyAzure, Mark, lucascaro, Nguyễn Thanh Tú Nov 20 '18 at 7:40


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.























    0















    My question is how can I send the driver of my web api to make an insert to my database from node js ?, the web api is in visual studio and the node js in visual studio code. An acquaintance says that with a request I can do it, but I am very confused on how it should be done. If anyone can help I'd appreciate it.










    share|improve this question













    closed as too broad by SherylHohman, CozyAzure, Mark, lucascaro, Nguyễn Thanh Tú Nov 20 '18 at 7:40


    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





















      0












      0








      0








      My question is how can I send the driver of my web api to make an insert to my database from node js ?, the web api is in visual studio and the node js in visual studio code. An acquaintance says that with a request I can do it, but I am very confused on how it should be done. If anyone can help I'd appreciate it.










      share|improve this question














      My question is how can I send the driver of my web api to make an insert to my database from node js ?, the web api is in visual studio and the node js in visual studio code. An acquaintance says that with a request I can do it, but I am very confused on how it should be done. If anyone can help I'd appreciate it.







      javascript html node.js asp.net-web-api bootstrap-4






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 2:47









      Leon9091Leon9091

      1




      1




      closed as too broad by SherylHohman, CozyAzure, Mark, lucascaro, Nguyễn Thanh Tú Nov 20 '18 at 7:40


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









      closed as too broad by SherylHohman, CozyAzure, Mark, lucascaro, Nguyễn Thanh Tú Nov 20 '18 at 7:40


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


























          2 Answers
          2






          active

          oldest

          votes


















          1














          https://www.w3schools.com/nodejs/nodejs_mysql.asp:



          var mysql = require('mysql');

          var con = mysql.createConnection({
          host: "localhost",
          user: "yourusername",
          password: "yourpassword",
          database: "mydb"
          });

          con.connect(function(err) {
          if (err) throw err;
          console.log("Connected!");
          var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
          con.query(sql, function (err, result) {
          if (err) throw err;
          console.log("1 record inserted");
          });
          });


          Then simply run the file from the terminal. I know on lunix it's $ node file.js






          share|improve this answer
























          • but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

            – Leon9091
            Nov 20 '18 at 2:53













          • It should be the same thing, I think.

            – BGM52
            Nov 20 '18 at 2:54











          • the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

            – Leon9091
            Nov 20 '18 at 2:57











          • What OS are you using?

            – BGM52
            Nov 20 '18 at 2:57











          • I'm using windows

            – Leon9091
            Nov 20 '18 at 3:01



















          0














          if you are using sql server, you can use tedious:



              const Request = require('tedious').Request;
          const Connection = require('tedious').Connection;

          const DB = {
          async connect() {
          const config = {
          userName: your username,
          password: your password,
          server: your host,
          options: {
          port: port,
          database: database,
          rowCollectionOnRequestCompletion: true,
          rowCollectionOnDone: true,
          },
          };
          return new Promise((resolve, reject) => {
          const connection = new Connection(config);
          connection.on('connect', (err) => {
          if (err) {
          console.log(`connect error: ${err.message}`);
          reject(err);
          } else {
          resolve(connection);
          }
          });
          });
          },
          async request(sql) {
          const connection = await DB.connect();
          return new Promise((resolve, reject) => {
          connection.execSql(new Request(sql, (error, rowCount, rows) => {
          connection.close();
          if (error) {
          reject(error);
          } else {
          resolve({
          rowCount,
          rows
          });
          }
          }));
          });
          },
          };

          module.exports = DB;





          share|improve this answer
























          • If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

            – Leon9091
            Nov 20 '18 at 3:32











          • I must send call the procedures and the database from node, but my database is in the web api of visual studio

            – Leon9091
            Nov 20 '18 at 3:36











          • I have an example, but it will not let me upload the code

            – Leon9091
            Nov 20 '18 at 3:41


















          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          https://www.w3schools.com/nodejs/nodejs_mysql.asp:



          var mysql = require('mysql');

          var con = mysql.createConnection({
          host: "localhost",
          user: "yourusername",
          password: "yourpassword",
          database: "mydb"
          });

          con.connect(function(err) {
          if (err) throw err;
          console.log("Connected!");
          var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
          con.query(sql, function (err, result) {
          if (err) throw err;
          console.log("1 record inserted");
          });
          });


          Then simply run the file from the terminal. I know on lunix it's $ node file.js






          share|improve this answer
























          • but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

            – Leon9091
            Nov 20 '18 at 2:53













          • It should be the same thing, I think.

            – BGM52
            Nov 20 '18 at 2:54











          • the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

            – Leon9091
            Nov 20 '18 at 2:57











          • What OS are you using?

            – BGM52
            Nov 20 '18 at 2:57











          • I'm using windows

            – Leon9091
            Nov 20 '18 at 3:01
















          1














          https://www.w3schools.com/nodejs/nodejs_mysql.asp:



          var mysql = require('mysql');

          var con = mysql.createConnection({
          host: "localhost",
          user: "yourusername",
          password: "yourpassword",
          database: "mydb"
          });

          con.connect(function(err) {
          if (err) throw err;
          console.log("Connected!");
          var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
          con.query(sql, function (err, result) {
          if (err) throw err;
          console.log("1 record inserted");
          });
          });


          Then simply run the file from the terminal. I know on lunix it's $ node file.js






          share|improve this answer
























          • but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

            – Leon9091
            Nov 20 '18 at 2:53













          • It should be the same thing, I think.

            – BGM52
            Nov 20 '18 at 2:54











          • the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

            – Leon9091
            Nov 20 '18 at 2:57











          • What OS are you using?

            – BGM52
            Nov 20 '18 at 2:57











          • I'm using windows

            – Leon9091
            Nov 20 '18 at 3:01














          1












          1








          1







          https://www.w3schools.com/nodejs/nodejs_mysql.asp:



          var mysql = require('mysql');

          var con = mysql.createConnection({
          host: "localhost",
          user: "yourusername",
          password: "yourpassword",
          database: "mydb"
          });

          con.connect(function(err) {
          if (err) throw err;
          console.log("Connected!");
          var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
          con.query(sql, function (err, result) {
          if (err) throw err;
          console.log("1 record inserted");
          });
          });


          Then simply run the file from the terminal. I know on lunix it's $ node file.js






          share|improve this answer













          https://www.w3schools.com/nodejs/nodejs_mysql.asp:



          var mysql = require('mysql');

          var con = mysql.createConnection({
          host: "localhost",
          user: "yourusername",
          password: "yourpassword",
          database: "mydb"
          });

          con.connect(function(err) {
          if (err) throw err;
          console.log("Connected!");
          var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
          con.query(sql, function (err, result) {
          if (err) throw err;
          console.log("1 record inserted");
          });
          });


          Then simply run the file from the terminal. I know on lunix it's $ node file.js







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 2:52









          BGM52BGM52

          378




          378













          • but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

            – Leon9091
            Nov 20 '18 at 2:53













          • It should be the same thing, I think.

            – BGM52
            Nov 20 '18 at 2:54











          • the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

            – Leon9091
            Nov 20 '18 at 2:57











          • What OS are you using?

            – BGM52
            Nov 20 '18 at 2:57











          • I'm using windows

            – Leon9091
            Nov 20 '18 at 3:01



















          • but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

            – Leon9091
            Nov 20 '18 at 2:53













          • It should be the same thing, I think.

            – BGM52
            Nov 20 '18 at 2:54











          • the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

            – Leon9091
            Nov 20 '18 at 2:57











          • What OS are you using?

            – BGM52
            Nov 20 '18 at 2:57











          • I'm using windows

            – Leon9091
            Nov 20 '18 at 3:01

















          but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

          – Leon9091
          Nov 20 '18 at 2:53







          but I'm using sql server, not mysql, and the connection and procedures, I have them in the web visual studio api

          – Leon9091
          Nov 20 '18 at 2:53















          It should be the same thing, I think.

          – BGM52
          Nov 20 '18 at 2:54





          It should be the same thing, I think.

          – BGM52
          Nov 20 '18 at 2:54













          the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

          – Leon9091
          Nov 20 '18 at 2:57





          the professor said that the information should be sent in this way: html> Javascript> Node.js> Web Api> SQL

          – Leon9091
          Nov 20 '18 at 2:57













          What OS are you using?

          – BGM52
          Nov 20 '18 at 2:57





          What OS are you using?

          – BGM52
          Nov 20 '18 at 2:57













          I'm using windows

          – Leon9091
          Nov 20 '18 at 3:01





          I'm using windows

          – Leon9091
          Nov 20 '18 at 3:01













          0














          if you are using sql server, you can use tedious:



              const Request = require('tedious').Request;
          const Connection = require('tedious').Connection;

          const DB = {
          async connect() {
          const config = {
          userName: your username,
          password: your password,
          server: your host,
          options: {
          port: port,
          database: database,
          rowCollectionOnRequestCompletion: true,
          rowCollectionOnDone: true,
          },
          };
          return new Promise((resolve, reject) => {
          const connection = new Connection(config);
          connection.on('connect', (err) => {
          if (err) {
          console.log(`connect error: ${err.message}`);
          reject(err);
          } else {
          resolve(connection);
          }
          });
          });
          },
          async request(sql) {
          const connection = await DB.connect();
          return new Promise((resolve, reject) => {
          connection.execSql(new Request(sql, (error, rowCount, rows) => {
          connection.close();
          if (error) {
          reject(error);
          } else {
          resolve({
          rowCount,
          rows
          });
          }
          }));
          });
          },
          };

          module.exports = DB;





          share|improve this answer
























          • If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

            – Leon9091
            Nov 20 '18 at 3:32











          • I must send call the procedures and the database from node, but my database is in the web api of visual studio

            – Leon9091
            Nov 20 '18 at 3:36











          • I have an example, but it will not let me upload the code

            – Leon9091
            Nov 20 '18 at 3:41
















          0














          if you are using sql server, you can use tedious:



              const Request = require('tedious').Request;
          const Connection = require('tedious').Connection;

          const DB = {
          async connect() {
          const config = {
          userName: your username,
          password: your password,
          server: your host,
          options: {
          port: port,
          database: database,
          rowCollectionOnRequestCompletion: true,
          rowCollectionOnDone: true,
          },
          };
          return new Promise((resolve, reject) => {
          const connection = new Connection(config);
          connection.on('connect', (err) => {
          if (err) {
          console.log(`connect error: ${err.message}`);
          reject(err);
          } else {
          resolve(connection);
          }
          });
          });
          },
          async request(sql) {
          const connection = await DB.connect();
          return new Promise((resolve, reject) => {
          connection.execSql(new Request(sql, (error, rowCount, rows) => {
          connection.close();
          if (error) {
          reject(error);
          } else {
          resolve({
          rowCount,
          rows
          });
          }
          }));
          });
          },
          };

          module.exports = DB;





          share|improve this answer
























          • If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

            – Leon9091
            Nov 20 '18 at 3:32











          • I must send call the procedures and the database from node, but my database is in the web api of visual studio

            – Leon9091
            Nov 20 '18 at 3:36











          • I have an example, but it will not let me upload the code

            – Leon9091
            Nov 20 '18 at 3:41














          0












          0








          0







          if you are using sql server, you can use tedious:



              const Request = require('tedious').Request;
          const Connection = require('tedious').Connection;

          const DB = {
          async connect() {
          const config = {
          userName: your username,
          password: your password,
          server: your host,
          options: {
          port: port,
          database: database,
          rowCollectionOnRequestCompletion: true,
          rowCollectionOnDone: true,
          },
          };
          return new Promise((resolve, reject) => {
          const connection = new Connection(config);
          connection.on('connect', (err) => {
          if (err) {
          console.log(`connect error: ${err.message}`);
          reject(err);
          } else {
          resolve(connection);
          }
          });
          });
          },
          async request(sql) {
          const connection = await DB.connect();
          return new Promise((resolve, reject) => {
          connection.execSql(new Request(sql, (error, rowCount, rows) => {
          connection.close();
          if (error) {
          reject(error);
          } else {
          resolve({
          rowCount,
          rows
          });
          }
          }));
          });
          },
          };

          module.exports = DB;





          share|improve this answer













          if you are using sql server, you can use tedious:



              const Request = require('tedious').Request;
          const Connection = require('tedious').Connection;

          const DB = {
          async connect() {
          const config = {
          userName: your username,
          password: your password,
          server: your host,
          options: {
          port: port,
          database: database,
          rowCollectionOnRequestCompletion: true,
          rowCollectionOnDone: true,
          },
          };
          return new Promise((resolve, reject) => {
          const connection = new Connection(config);
          connection.on('connect', (err) => {
          if (err) {
          console.log(`connect error: ${err.message}`);
          reject(err);
          } else {
          resolve(connection);
          }
          });
          });
          },
          async request(sql) {
          const connection = await DB.connect();
          return new Promise((resolve, reject) => {
          connection.execSql(new Request(sql, (error, rowCount, rows) => {
          connection.close();
          if (error) {
          reject(error);
          } else {
          resolve({
          rowCount,
          rows
          });
          }
          }));
          });
          },
          };

          module.exports = DB;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 3:24









          pengpeng

          234




          234













          • If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

            – Leon9091
            Nov 20 '18 at 3:32











          • I must send call the procedures and the database from node, but my database is in the web api of visual studio

            – Leon9091
            Nov 20 '18 at 3:36











          • I have an example, but it will not let me upload the code

            – Leon9091
            Nov 20 '18 at 3:41



















          • If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

            – Leon9091
            Nov 20 '18 at 3:32











          • I must send call the procedures and the database from node, but my database is in the web api of visual studio

            – Leon9091
            Nov 20 '18 at 3:36











          • I have an example, but it will not let me upload the code

            – Leon9091
            Nov 20 '18 at 3:41

















          If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

          – Leon9091
          Nov 20 '18 at 3:32





          If I use sql server, but I do not do anything from the node js, I have a connection between the node js and the web api, it is assumed that in the node js I send everything from the web api, not from sql server directly

          – Leon9091
          Nov 20 '18 at 3:32













          I must send call the procedures and the database from node, but my database is in the web api of visual studio

          – Leon9091
          Nov 20 '18 at 3:36





          I must send call the procedures and the database from node, but my database is in the web api of visual studio

          – Leon9091
          Nov 20 '18 at 3:36













          I have an example, but it will not let me upload the code

          – Leon9091
          Nov 20 '18 at 3:41





          I have an example, but it will not let me upload the code

          – Leon9091
          Nov 20 '18 at 3:41



          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?