This is the video to get SQL Server data using node.js and also
in this video you will see the solution of below errors,
1. Failed to connect to localhost:1433 - Could not connect (sequence).
This is fetch SQL data using node js
or
get SQL data using node js
if you got error Cannot find module 'express' then run command on command prompt
npm install express
if you got error Cannot find module 'mssql' then run command on command prompt
npm install mssql
1. create table
CREATE TABLE [dbo].[tblprod](
[prodcode] [int] NOT NULL,
[prodname] [nchar](10) NULL
)
2. server.js code
var express = require('express');
var app = express();
app.get('/', function (req, res) {
var sql = require("mssql");
// config for your database
var config = {
user: 'sa',
password: 'abc!1234',
server: 'localhost',
database: 'sample'
};
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select prodcode,prodname from tblprod ', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});
Watch video Acess SQL server Data in node js/Failed to connect to localhost:1433 - Could not connect (sequence) online without registration, duration hours minute second in high quality. This video was added by user timeoutexpired 16 April 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 6,908 once and liked it 37 people.