How to connect to Microsoft Fabric Lakehouse from Node.js using AAD Service Principal (like pyodbc in Python)?

Tejesh Reddy 5 Reputation points
2025-08-04T11:56:49.31+00:00

Hi Team,

I am trying to connect to a Microsoft Fabric Lakehouse (via SQL endpoint) using a Node.js application, similar to how it's done in Python using pyodbc and an Azure AD service principal.

In Python, I’m able to connect like this:

import logging

 import urllib.parse from sqlalchemy 

import create_engine, text

 import pandas as pd

odbc_str = ( f"Driver={DRIVER};" f"Server=tcp:{SERVER},1433;" f"Database={DATABASE};" f"UID={CLIENT_ID}@{TENANT_ID};" f"PWD={CLIENT_SECRET};" "Authentication=ActiveDirectoryServicePrincipal;" ) conn_url = "mssql+pyodbc:///?odbc_connect=" + urllib.parse.quote_plus(odbc_str) print(f"Connecting with URL: {conn_url}")

I want to do the same in Node.js, but the odbc package in Node doesn't accept Authentication=ActiveDirectoryServicePrincipal in the connection string.

My Questions:

What is the recommended method to connect to Microsoft Fabric Lakehouse using Node.js + ODBC + AAD Service Principal?

Can Microsoft provide an updated example for Node.js or JavaScript similar to the working Python version?

  1. If not possible via Node ODBC, is there a REST API or SQL proxy endpoint that can be called with a bearer token (access_token) from Node.js?
Azure Service Fabric
Azure Service Fabric
An Azure service that is used to develop microservices and orchestrate containers on Windows and Linux.
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Dominic Dreier 0 Reputation points
    2025-08-07T09:28:21.5333333+00:00

    Hey there,

    i am having the same problem - more informations would be awesome!

    0 comments No comments

  2. ADAM SHEPPARD 0 Reputation points
    2025-08-14T17:01:31.4833333+00:00

    Hi there - I struggled with this using the mssql and tedious packages, tried using the optional msnodesqlv8 package with mssql, pored through debug logs and the mssql/tedious packages themselves, and am thoroughly convinced that any current solution cannot rely on those packages. However, here is a solution using the msnodesqlv8 package and the latest ODBC driver 18 for SQL Server without tedious or mssql.

    
    const sql = require('msnodesqlv8');
    
    // Connection string for Azure SQL (Lakehouse)
    const connectionString = `
      Driver={ODBC Driver 18 for SQL Server};
      Server=<your-endpoint.datawarehouse.fabric.microsoft.com>;
      Database=<your-database-name>;
      Authentication=ActiveDirectoryServicePrincipal;
      UID=<your-app-registration-id>@<your-tenant-id>;
      PWD=<your-app-registration-secret>;
    `;
    
    const query = 'SELECT TOP 10 * FROM sys.tables';
    
    sql.open(connectionString, (err, conn) => {
      if (err) {
        console.error('Connection error:', err);
        return;
      }
      conn.query(query, (err, rows) => {
        if (err) {
          console.error('Query error:', err);
        } else {
          console.log('Query results:', rows);
        }
        conn.close();
      });
    });
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.