简体   繁体   中英

How should I configure the a connection to MS Azure cloud database using pyodbc?

I'm setting up a python script to connect to an instance of the azure cloud database, and seeing a difference in the connection when I use IDLE vs when I try to execute the connection from a script. For example, when I do the following in IDLE:

>>> import pyodbc
>>> conn = pyodbc.connect('DRIVER={SQL Server};SERVER=<my.database.host.info>,1433', user='<my_username@mydatabase', password='password', database='database')

I'm able connect successfully and execute a basic query against one of the tables in the database.

However when I use the same connection string (copied from the IDLE console) in a script, I get the following error:

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Usually, the issue is raised because the 32/64 bit version of python environment and odbc driver are mismatched.

You may check the python version and odbc driver version you used to run the script. You have to manage to change both of them need to be 32-bit (or both 64-bit) in order for this to work.

You can get the specified version of pyodbc extension from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc .

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