Forum Discussion
SaharRad
1 year agoRegular Visitor
Sql database in Fabric
Hi everyone, I’m trying to connect an ODBC data source to a SQL Database in Microsoft Fabric, but I’m facing this error: Microsoft ODBC Driver for SQL Server Version 18.04.0001 Running conne...
- 1 year ago
Thank you for the response.
I followed all the suggested steps:
- Confirmed DNS and network connectivity (nslookup, Test-NetConnection).
- Verified I have ODBC Driver 18 and pyodbc installed.
- Ran my Python script with ActiveDirectoryInteractive and also tried other auth methods.
- Checked my Azure tenant and found I have no valid subscription assigned or active.
It turns out my subscription status is causing the issue. I don’t have any active Azure subscription in my tenant.
dlevy
1 year agoMicrosoft Employee
Hi OliverO - Here is an example using pyodbc but the connection string is the same for sqlalchemy.
"""
Connects to a SQL database using pyodbc
"""
import pyodbc
connectionString = f'DRIVER={{ODBC Driver 18 for SQL Server}};Server=tcp:<redacted>.database.windows.net,1433;Database=<redacted>;Encrypt=yes;TrustServerCertificate=no;Authentication=ActiveDirectoryInteractive'
conn = pyodbc.connect(connectionString)
SQL_QUERY = """
SELECT
TOP 5 c.CustomerID,
c.CompanyName,
COUNT(soh.SalesOrderID) AS OrderCount
FROM
SalesLT.Customer AS c
LEFT OUTER JOIN SalesLT.SalesOrderHeader AS soh ON c.CustomerID = soh.CustomerID
GROUP BY
c.CustomerID,
c.CompanyName
ORDER BY
OrderCount DESC;
"""
cursor = conn.cursor()
cursor.execute(SQL_QUERY)
records = cursor.fetchall()
for r in records:
print(f"{r.CustomerID}\t{r.OrderCount}\t{r.CompanyName}")
This works with the AdventureWorks sample data. Make sure to include the entire server and database names, including GUIDs.
OliverO
1 year agoHelper III
Thanks Mr Levy! I will try this tomorrow