问题描述
widows环境下我用pyodbc连接mssql , pyodbc版本为:pyodbc-2.1.8.win32-py2.7.exe python为:2.7pyodbc安装到python目录成功后,连接代码如下import urllib2from BeautifulSoup import BeautifulSoup,Tagimport reimport osimport stat#import MySQLdbimport pyodbcsource = 'DRIVER={SQL Server};SERVER=.;DATABASE=test;UID=sa;PWD=123456'db = pyodbc.connect(source)cursor = db.cursor()cursor.execute('select url,term from html_url where term="103"')for i in cursor.fetchall():url_str=str(i[0])print url_str报错信息:请问可能是什么原因造成的, 感激不尽
解决方案
是不是pyodbc没有安装成功啊?在你的python的Libsite-packages目录下边有pyodbc.pyd这个文件吗?如果安装成功,你可以试一下最简单的例子:#!/usr/bin/python# coding=gbk"""Mainly used to manipulate the common database."""import pyodbc"""return the datasource list of local machine"""def listDSNs(): return pyodbc.dataSources()if __name__ == '__main__': #src = 'DRIVER={SQL Server};SERVER=.;DATABASE=test;UID=sa;PWD=123456' src = 'DSN=sampledb;UID=dba;pwd=sql' db = pyodbc.connect(src) cursor = db.cursor() cursor.execute('select 1') for i in cursor.fetchall(): url_str=str(i[0]) print url_str db.close()