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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
P_work
New Contributor III

Using pyodbc in python 3.11 notebook

If one uses pyodbc to write to and read from several Fabric SQL DB tables and read from several Lakehouse  "tables"  using SQL Endpoint, from within a single notebook, any caveats or pointers? Specifically connections? I am wary of using connection pool. Certainly, I can see a single connection utilized for queries to reduce load on SQL Server,  perhaps with a with statement.

 

 

1 ACCEPTED SOLUTION
v-veshwara-msft
Honored Contributor II

Hi @P_work ,

Thanks for the follow up.

As @Vinodh247 already mentioned, keeping long running global connections is not recommended because the SQL analytics endpoint can become idle and drop sessions in the background. The Microsoft documentation notes that the endpoint can be suspended after inactivity:
https://learn.microsoft.com/en-us/fabric/data-warehouse/sql-analytics-endpoint-performance 

 

In that case a reused pyodbc connection may fail since pyodbc does not automatically recover when the backend session is dropped.

There are similar reports in the community where idle connections to the lakehouse SQL endpoint resulted in errors:
Solved: Failed to access/connect to Lakehouse SQL Endpoint... - Microsoft Fabric Community

 

To reduce repeated reconnect times you can keep related queries inside the same connection block and optionally add a simple retry approach for transient disconnects.

 

Hope this helps. Please reach out for further assistance.

Thank you.

View solution in original post

5 REPLIES 5
Vinodh247
Contributor III

Pyodbc does not give you a native connection pool, and you do not want one inside fabric notebooks anyway. Use one connection per endpoint (one for fabric SQLDB, one for lakehouse SQL endpoint). Do not pool. Wrap every operation in a with block so the connection opens, executes, and closes cleanly. Avoid long lived or global connections because Fabric endpoints drop idle sessions and pyodbc does not auto-recover well.

 

Please 'Kudos' and 'Accept as Solution' if this answered your query.

Regards,
Vinodh
Microsoft MVP [Fabric]
LI: https://www.linkedin.com/in/vinodh-kumar-173582132
Blog: vinsdata.in
P_work
New Contributor III

One issue when not using global connections is that SQL Analytics Endpoint appears to require upwards of four seconds to connect. Any specifics regarding dropping of idle sessions? i.e. Opening a global connection and have it close when notebook session ends would alleviate this issue.

v-veshwara-msft
Honored Contributor II

Hi @P_work ,

Thanks for the follow up.

As @Vinodh247 already mentioned, keeping long running global connections is not recommended because the SQL analytics endpoint can become idle and drop sessions in the background. The Microsoft documentation notes that the endpoint can be suspended after inactivity:
https://learn.microsoft.com/en-us/fabric/data-warehouse/sql-analytics-endpoint-performance 

 

In that case a reused pyodbc connection may fail since pyodbc does not automatically recover when the backend session is dropped.

There are similar reports in the community where idle connections to the lakehouse SQL endpoint resulted in errors:
Solved: Failed to access/connect to Lakehouse SQL Endpoint... - Microsoft Fabric Community

 

To reduce repeated reconnect times you can keep related queries inside the same connection block and optionally add a simple retry approach for transient disconnects.

 

Hope this helps. Please reach out for further assistance.

Thank you.

Hi @P_work ,
Just wanted to check if the response provided was helpful. If further assistance is needed, please reach out.
Thank you.

v-veshwara-msft
Honored Contributor II

Hi @P_work ,

Just checking in to see if you query is resolved and if any responses were helpful.
Otherwise, feel free to reach out for further assistance.

Thank you.

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Free Fabric Certifications

Free Fabric Certifications

Get Fabric certified for free! Don't miss your chance.

January Fabric Update Carousel

Fabric Monthly Update - January 2026

Check out the January 2026 Fabric update to learn about new features.

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.

Users online (7,728)