Forum Discussion

Omar_Osman's avatar
Omar_Osman
Advocate I
2 years ago

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;

var config = {
  server:
    //"****.datawarehouse.pbidedicated.windows.net",
    "*****.datawarehouse.fabric.microsoft.com",
  database: "Gold",
  options: {
    encrypt: true,
    trustServerCertificate: false,
  },
  authentication: {
    //type: "azure-active-directory-password",
    type: "azure-active-directory-service-principal-secret",
    options: {
      //userName: "@.onmicrosoft.com",
      //password: "****",
      clientId: "****",
      tenantId: "****",
      clientSecret: "****",
    },
  },
};

var connection = new Connection(config);

connection.connect((err) => {
  if (err) {
    console.log("Connection Failed");
    throw err;
  }

  console.log("Custom connection Succeeded");
  connection.close();
});

 

 

 Problem description
Got an error message when connecting to Microsoft Fabric SQL Endpoint

 

 

ConnectionError: Connection lost - socket hang up
     {at Connection.socketError
... node_modules\tedious\lib\connection.js:1344:26)
    code: 'ESOCKET'
  }

 

 


Note:that the connection works when using the powershell with the same parameters.

 

 

Install-Module -Name SqlServer
$connectionString = "Server=$server;Database=$database;User Id=$username;Password=$password;Authentication=Active Directory Password;Encrypt=True;TrustServerCertificate=False;"
# Create a SQL connection
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = $connectionString

 

 


Best Regards,