Omar_Osman
Advocate I
2 years agoStatus:
Investigating
ERROR - Connect to SQL Endpoint using Node.js and tedious npm package.
Unsuccessful connect to SQL Endpoint using Node.js and tedious or mssql npm package Software versions tedious: "^17.0.0" Node.js:18.17.1 var Connection = require("tedious").Connection...
erz1234
2 years agoRegular Visitor
Hey MAXI2799, your issue might be a bit different then ours. I say that because I have no problem connecting to SQL Server with mssql. Maybe I am wrong though, as I have not try to connect to 2022 version. So if the issue you have is the same as with connecting to Fabric, I found library odbc, that connects successfully to fabric dwh. As it turns out (or so i have read), tedious library can't connect to fabric dwh because fabric has a bit different security layers and protocols, that tedious so far do not have.
ODBC library code that works for me:
import * as dotenv from 'dotenv';
import odbc from 'odbc';
// Load environment variables from .env file
dotenv.config();
const tenantId = process.env.AZURE_TENANT || '';
const clientId = process.env.AZURE_APP_CLIENT_ID || '';
const clientSecret = process.env.AZURE_APP_SECRET || '';
const dbServer = process.env.DB_SERVER || ''; // <server_name>.datawarehouse.fabric.microsoft.com
const database = process.env.DB_NAME || '';
if (!tenantId || !clientId || !clientSecret || !dbServer || !database) {
throw new Error("Missing required environment variables");
}
async function connectToDatabase() {
const connectionString = `
Driver={ODBC Driver 17 for SQL Server};
Server=${dbServer};
Database=${database};
UID=${clientId};
PWD=${clientSecret};
Authentication=ActiveDirectoryServicePrincipal;
Encrypt=yes;
TrustServerCertificate=no;
Connection Timeout=30;
`;
try {
const connection = await odbc.connect(connectionString);
console.log('Connection established!');
// Your query execution code here
const result = await connection.query('SELECT 1');
console.log(result);
// Close the connection
await connection.close();
console.log('Connection closed');
} catch (error) {
console.error('ODBC Error:', error);
}
}
For tedious library, this is the link where I found most usefull information - https://github.com/tediousjs/tedious/issues/1563