将python 3.3连接到microsoft sql server 2008

将python 3.3连接到microsoft sql server 2008,python,sql-server-2008,python-3.x,pydev,Python,Sql Server 2008,Python 3.x,Pydev,我是python新手。我在我的Windows机器上使用带有Eclipse的Pydev IDE进行python编程。我正在使用Python3.3 vern,希望与MS Sql Server 2008连接。有人能建议我如何连接MS Sql Server 2008吗 支持python3,可以连接到任何wich数据库,其中有一个odbc驱动程序,包括sql服务器 还有一个纯python实现,它也应该支持python3 还声称与python3合作 您可以找到一个包含更多选项的列表。我将用一个PyODBC示

我是python新手。我在我的Windows机器上使用带有Eclipse的Pydev IDE进行python编程。我正在使用Python3.3 vern,希望与MS Sql Server 2008连接。有人能建议我如何连接MS Sql Server 2008吗

支持python3,可以连接到任何wich数据库,其中有一个odbc驱动程序,包括sql服务器

还有一个纯python实现,它也应该支持python3

还声称与python3合作


您可以找到一个包含更多选项的列表。

我将用一个PyODBC示例来补充mata的答案

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()
导入pyodbc
连接_string='Driver={SQLServer本机客户端11.0};服务器=;数据库=;Uid=;Pwd=;'
connection=pyodbc.connect(连接字符串)
SQL='SELECT*FROM'
cur=connection.cursor()
当前执行(SQL)
当前关闭()
连接。关闭()
import pyodbc
server = 'SERVIDORNOMEOUIP'
database = 'MEUBANCO'
username = 'USERSQL'
password = 'SENHASQL'

#for SQL Server 2008
driver='{SQL Server Native Client 10.0}'

cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password + ';')

cursor = cnxn.cursor()

cursor.execute("SELECT nome,senha FROM [tabusuariosenha]")

row = cursor.fetchone()
print ("CAMPO1  |  CAMPO2 " )
while row:
    print (str(row[0]) + " " + str(row[1]))
    row = cursor.fetchone()