简体   繁体   中英

('IM004', “[IM004] [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed (0) (SQLDriverConnect)”) error

Searched around, but all the other replies seem to be about Oracle, so I decided to create a new post.

I'm currently trying to connect Python to my SQL Server database using the code provided by Microsoft and the pyodbc library. Code as follows.

import pyodbc 

server = 'server.database.windows.net' 
database = 'testing' 
username = 'user' 
password = 'password' 
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL 
Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ 
password)
cursor = cnxn.cursor()

This error message comes out.

Exception has occurred: Error
('IM004', "[IM004] [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle 
on SQL_HANDLE_ENV failed (0) (SQLDriverConnect)")

What should I change?

I had the same issue on Windows after upgrading an 'old' SQL Server 2017 client to the last one. Repairing 'Microsoft ODBC Driver 17 for SQL Server' fixed the problem for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM