admin管理员组文章数量:1397175
First I ahve used Node.js and tedious but it didn't work becase 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. Now I have used ODBC library but got Authentication Error
Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Could not login because the authentication failed.
I am using this code in node js
require('dotenv').config();
const express = require('express');
const odbc = require('odbc');
const app = express();
const port = process.env.PORT || 3000;
// Connection pool configuration
const poolConfig = {
connectionString: `
Driver={ODBC Driver 18 for SQL Server};
Server=${process.env.DB_SERVER};
Database=${process.env.DB_NAME};
UID=${process.env.AZURE_APP_CLIENT_ID};
PWD=${process.env.AZURE_APP_SECRET};
Authentication=ActiveDirectoryServicePrincipal;
Encrypt=yes;
TrustServerCertificate=no;
Connection Timeout=30;
`.replace(/\n\s+/g, ' '), // Clean up whitespace
initialSize: 5,
maxSize: 20
};
// Create connection pool
let pool;
(async () => {
try {
pool = await odbc.pool(poolConfig);
console.log('Connection pool created successfully');
} catch (error) {
console.error('Pool creation failed:', error);
process.exit(1);
}
})();
// Basic health check
app.get('/', (req, res) => {
res.send('Fabric DWH API is running');
});
// Query endpoint
app.get('/api/query', async (req, res) => {
try {
const query = req.query.sql || 'SELECT TOP 10 * FROM INFORMATION_SCHEMA.TABLES';
const connection = await pool.connect();
const result = await connection.query(query);
await connection.close();
res.json(result);
} catch (error) {
console.error('Query error:', error);
res.status(500).json({ error: error.message });
}
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
using python
import pyodbc
import struct
from itertools import chain, repeat
from azure.identity import ClientSecretCredential
def connect_to_fabric():
tenant_id = "your-tenant-id"
client_id = "your-client-id"
client_secret = "your-client-secret"
database_server = "your-server.datawarehouse.fabric.microsoft,1433"
database_name = "your-database-name"
credential = ClientSecretCredential(
tenant_id=tenant_id,
client_id=client_id,
client_secret=client_secret
)
token = credential.get_token("/.default").token
token_bytes = token.encode("UTF-16-LE")
encoded = bytes(chain.from_iterable(zip(token_bytes, repeat(0))))
token_struct = struct.pack(f'<I{len(encoded)}s', len(encoded), encoded)
SQL_COPT_SS_ACCESS_TOKEN = 1256
connection_string = f"""
Driver={{ODBC Driver 18 for SQL Server}};
Server={database_server};
Database={database_name};
Encrypt=yes;
TrustServerCertificate=no;
Connection Timeout=45;
"""
try:
print("
本文标签:
版权声明:本文标题:sql - Getting Authentication failed error while connecting with MS Fabric data Warehouse Using Node js and Python - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1744130540a2592160.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论