Forum Discussion

P_work's avatar
P_work
Helper I
9 months ago
Solved

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.

 

 

5 Replies

  • 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.

     

  • 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.

  • 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.