I have created a sample api that connects to my Microsoft Sql Server. I have used the following code to do so,
var express = require("express");
var app = express();
app.get("/", function (req, res) {
var sql = require("mssql/msnodesqlv8");
var config = {
driver: "msnodesqlv8",
connectionString:
"Driver={SQL Server Client 16.0};Server=.\LAPTOP-***;Database=Test;Trusted_Connection=yes;",
};
const pool = new sql.ConnectionPool(config)
.connect()
.then((pool) => {
return pool.request().query("Select * From dbo.Test123");
})
.then((result) => {
let rows = result.recordset;
res.status(200).json(rows);
sql.close();
})
.catch((err) => {
res.status(500).send({ message: `${err}` });
sql.close();
});
});
var server = app.listen(5000, function () {
console.log("Server is running..");
});
and i have been getting the following output in my localhost:5000,
{
“message”: “ConnectionError: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified”
}
I have tried the following above code and been trying to get the result of query in my console.