I encounter this error while testing my MSSQL-connected back-end project, which I created with Node.js, in IIS. My example MSSQL connection config file:
const config = {
server: "server name or IP address",
port: SQL Port,
user: "SQL Username",
password: "sql password.",
database: "sql database",
options: {
enableArithAbort: true,
},
};
Here are my codes at the endpoint where I got the error:
const express = require("express");
const mssql = require("mssql/msnodesqlv8");
const config = require("./config");
const app = express();
//Customers //
app.get("/getstok", function (req, res) {
mssql.connect(config, (error) => {
if (error) {
res.status(500).json({ error: "There was a problem with the MSSQL Connection", message: error.message });
} else {
const request = new mssql.Request();
const query = `
SELECT
STOCKCARD ID
FROM IPLIKKARISIM
`;
request.query(query, (error, results) => {
if (error) {
console.error("Query error", error);
res.status(500).json("SQL Query is not working properly.");
} else {
res.json(results.recordset);
}
});
}
});
});
app.listen(process.env.PORT);
Normally, when I try it on another server, it works without any problems. I think there is a deficiency in the system, etc., not related to the code, but I cannot solve this problem.
Downloading the SQL Server Native Client RDA 11.0 solved my problem.
I have these on my odbc data source manager screen and now my back-end endpoints connected to node.js and mssql are working with the iisnode library.