Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ashmitp869
Responsive Resident
Responsive Resident

Python not connecting with MS SQL Server

Hi All,

 

I have Power BI and Python install in my local machine , and the MS SQL server in install in Remote Desktop.

I install pypyodbc and pyodbc in local machine and trying to connect my db and tables by unable to do that.

 

code

 

 

mport pandas as pd
import numpy as np
import os

import datetime 

import pyodbc as odbc

DRIVER_NAME ='SQL SERVER'
SERVER_NAME= 'servername'
DATABASE_NAME = 'dbname'

connection_string =f"""
    DRIVER={{{DRIVER_NAME}}};
    SERVER={SERVER_NAME};
    DATABASE={DATABASE_NAME};
    Trust_Copnnection=yes;
"""

conn=odbc.connect(connection_string)
print(conn)

 

 

 getting this error :

PS C:\Users\sbhadra> & C:/Users/sbhadra/AppData/Local/Programs/Python/Python312/python.exe "c:/Users/sbhadra/AppData/Local/Programs/Python Scripts/DataManipulationWhile.py"
<pyodbc.Connection object at 0x0000020C9B21FB80>

 

Do I need to install MS SQL Server in my local machine and also the driver ?

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

you don't need the server, and the ODBC driver should be installed by default. Check the 64 bit ODBC data sources control panel.

 

Now - why Python? Why not the standard SQL Server connector in Power Query?

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

you don't need the server, and the ODBC driver should be installed by default. Check the 64 bit ODBC data sources control panel.

 

Now - why Python? Why not the standard SQL Server connector in Power Query?

Thanks for the reply @lbendlin .

I am unable to achieve the output via power query or dax as I have two tables with M:M relationship.

I need to pull Timesheet Date from the DSR table and check the Qualification table for Date Start,Date End and Date Expiry to give output if that employee is Qualifed, Learner or Not Qualified for the hours he registered in DSR table with Timesheet data.

 

Will you have a look on the sample file - I have provided the details

 

https://community.fabric.microsoft.com/t5/Power-Query/Need-help-with-Dax-to-calculated-from-two-diff...

Hi ,

I am using Python for data manipulation

You can still do that as part of the Powr Query script, AFTER you fetched the data from the SQL Server.

 

NOTE: As soon as you use Python or R scripts you will need to setup and maintain a Personal Gateway if you need scheduled refreshes.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.