本文主要是介绍python3.2使用pywin32连接SQLServer2008,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- # -*- coding: UTF-8 -*-
- import dbi, odbc
- db = odbc.odbc("dsn=data;uid=sa;pwd=master")
- print("登入成功")
- print('db:')#,type(db))
- c = db.cursor()
- print('c:')#,type(c))
- query="SELECT * FROM TESTTABLE"
- c.execute (query)
- rs = c.fetchall()# see also fetchone() and fetchmany()
- c.close()
- # looping over the results
- for r in rs:
- print(r)
- print('行的类型',type(r))
- for col in r:
- print(col,type(col))
- #print the name of column 0 of the result set
- print ('描述',c.description[0][0])
- #print the type, length, precision etc of column 1.
- print (c.description[1][1:5])
- db.close()
# -*- coding: UTF-8 -*-
import dbi, odbcdb = odbc.odbc("dsn=data;uid=sa;pwd=master")
print("登入成功")
print('db:')#,type(db))
c = db.cursor()
print('c:')#,type(c))
query="SELECT * FROM TESTTABLE"
c.execute (query)
rs = c.fetchall()# see also fetchone() and fetchmany()
c.close()
# looping over the results
for r in rs:print(r)print('行的类型',type(r))for col in r:print(col,type(col))
#print the name of column 0 of the result set
print ('描述',c.description[0][0])
#print the type, length, precision etc of column 1.
print (c.description[1][1:5])
db.close()
NND搞了一晚上,终于搞出来了,记录一下:
pywin32连接SQLServer,成功!
步骤:
1.首先建立ODBC数据源 odbcad32
2.使用pywin32的ODBC连接数据源,怎样操作数据库这里就不费口舌了。注意要写上用户名和密码,不然会报错:
dbi.opError: [Microsoft][SQL Server Native Client 10.0][SQL Server]用户 '' 登录失败。 in LOGIN
这篇关于python3.2使用pywin32连接SQLServer2008的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!