Connecting python 3.3 to microsoft sql server 2008

柔情痞子 提交于 2020-01-24 01:43:21

问题


I am new to python. I am using Pydev IDE with Eclipse for python programming in my Windows machine. I am using python 3.3 vern and want to connect with MS Sql Server 2008. Could someone suggest how should I connect with MS Sql Server 2008.


回答1:


pyodbc supports python3 and can connect to any databas for wich there's an odbc driver, including sql server.

There's also a pure python implementation pypyodbc which also should supoort python3.

adodbapi also claims to work with python3.

Here you can find a list with some more options.




回答2:


I will augment mata's answer with a pypyodbc example.

import pypyodbc
connection_string ='Driver={SQL Server Native Client 11.0};Server=<YOURSERVER>;Database=<YOURDATABASE>;Uid=<YOURUSER>;Pwd=<YOURPASSWORD>;'
connection = pypyodbc.connect(connection_string)
SQL = 'SELECT * FROM <YOURTABLE>'

cur = connection.cursor()
cur.execute(SQL)

cur.close()
connection.close()


来源:https://stackoverflow.com/questions/17411362/connecting-python-3-3-to-microsoft-sql-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!