server = 'tcp:myserver.database.windows.net'. # fabric lakehouse sql endpoint
database = 'mydb'
username = 'myusername'
pass1 = 'xxxx'
auth = 'ActiveDirectoryPassword'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';Authentication='+auth+';UID='+username+';PWD='+pass1+';ENCRYPT=yes;Trusted_Connection=yes')
cursor = cnxn.cursor()
" OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) "
Any help would be greatly appreciated.
OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0)
When the network is not allowing to connect to the server then you may get above error. Make sure your network is allowed to connect the server. Along with that according to the MS document
Only Microsoft Entra multifactor authentication (MFA) is supported.
So, when you are connecting to the server use ActiveDirectoryInteractive
option instead of ActiveDirectoryPassword
for authentication as mentioned in the below code:
import pyodbc
server = 'tcp:<serverName>.database.windows.net' # fabric lakehouse sqlendpoint
database = '<dbName>'
username = '<v-id>'
auth = 'ActiveDirectoryInteractive'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';Authentication='+auth+';UID='+username+';ENCRYPT=yes;')
cursor = cnxn.cursor()
when run the above code new window will open for authentication, complete the authentication, then you will be able to connect it successfully as shown below:
For more information you can refer to the MS document.