当前位置: 代码迷 >> SQL >> python3.2运用pywin32连接SQLServer2008
  详细解决方案

python3.2运用pywin32连接SQLServer2008

热度:102   发布时间:2016-05-05 13:00:06.0
python3.2使用pywin32连接SQLServer2008

# -*- 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 resultsfor 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 setprint ('描述',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

  相关解决方案