-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Describe the bug
The mssql-python driver fails to query Fabric DWs. Checked pyodbc to rule out underlying common code and it works fine.
Exception message:
DatabaseError: Execution failed on sql 'SELECT * FROM [dlevy-05072025].[SalesLT].[Address]': Driver Error: Syntax error or access violation; DDBC Error: [Microsoft][SQL Server]DECLARE CURSOR is not supported.
Stack trace:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
File c:\python\python-notebook-qs\.venv\Lib\site-packages\pandas\io\sql.py:2664, in SQLiteDatabase.execute(self, sql, params)
2663 try:
-> [2664](file:///C:/python/python-notebook-qs/.venv/Lib/site-packages/pandas/io/sql.py:2664) cur.execute(sql, *args)
2665 return cur
File c:\python\python-notebook-qs\.venv\Lib\site-packages\mssql_python\cursor.py:995, in Cursor.execute(self, operation, use_prepare, reset_cursor, *parameters)
992 try:
993
994 # Check for errors but don't raise exceptions for info/warning messages
--> [995](file:///C:/python/python-notebook-qs/.venv/Lib/site-packages/mssql_python/cursor.py:995) check_error(ddbc_sql_const.SQL_HANDLE_STMT.value, self.hstmt, ret)
996 except Exception as e:
File c:\python\python-notebook-qs\.venv\Lib\site-packages\mssql_python\helpers.py:78, in check_error(handle_type, handle, ret)
77 logger.error("Error: %s", error_info.ddbcErrorMsg)
---> [78](file:///C:/python/python-notebook-qs/.venv/Lib/site-packages/mssql_python/helpers.py:78) raise_exception(error_info.sqlState, error_info.ddbcErrorMsg)
File c:\python\python-notebook-qs\.venv\Lib\site-packages\mssql_python\exceptions.py:651, in raise_exception(sqlstate, ddbc_error)
650 logger.error(exception_class)
--> [651](file:///C:/python/python-notebook-qs/.venv/Lib/site-packages/mssql_python/exceptions.py:651) raise exception_class
652 raise DatabaseError(
653 driver_error=f"An error occurred with SQLSTATE code: {sqlstate}",
654 ddbc_error=f"{ddbc_error}" if ddbc_error else f"Unknown DDBC error",
655 )
...
2673 raise ex from inner_exc
2675 ex = DatabaseError(f"Execution failed on sql '{sql}': {exc}")
-> [2676](file:///C:/python/python-notebook-qs/.venv/Lib/site-packages/pandas/io/sql.py:2676) raise ex from exc
DatabaseError: Execution failed on sql 'SELECT * FROM [dlevy-05072025].[SalesLT].[Address]': Driver Error: Syntax error or access violation; DDBC Error: [Microsoft][SQL Server]DECLARE CURSOR is not supported.
To reproduce
import mssql_python
SQL_CONNECTION_STRING="Driver={ODBC Driver 18 for SQL Server};Server=;Encrypt=yes;TrustServerCertificate=no;Authentication=ActiveDirectoryIntegrated;"
with connect(SQL_CONNECTION_STRING) as conn: # type: ignore
data = pd.read_sql_query('SELECT * FROM [dlevy-05072025].[SalesLT].[Address]', conn)
# Set the style - use print(plt.style.available) to see all options
print(data)
### Expected behavior
import pyodbc as py
SQL_CONNECTION_STRING="Driver={ODBC Driver 18 for SQL Server};Server=;Encrypt=yes;TrustServerCertificate=no;Authentication=ActiveDirectoryIntegrated;"
with py.connect(SQL_CONNECTION_STRING) as conn: # type: ignore
data = pd.read_sql_query('SELECT * FROM [dlevy-05072025].[SalesLT].[Address]', conn)
# Set the style - use print(plt.style.available) to see all options
print(data)
### Further technical details
Python version: 3.11.13
SQL Server version: Fabric DW
Operating system: Windows 11
**Additional context**
Reported by customer trying to connect to Synapse DW