pyodbc.Error'IM002'连接到DB2 [英] pyodbc.Error 'IM002' connecting to DB2

查看:3599
本文介绍了pyodbc.Error'IM002'连接到DB2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了Python 2.7( python-2.7.1.amd64.msi )和pyodbc,用于连接到DB2数据库的python扩展模块(即 pyodbc-2.1.8.win- amd64-py2.7.exe



我写了如下所示的示例脚本。

  import csv 
import pyodbc
conn = pyodbc.connectpyodbc.connect('DRIVER = {DB2}; SERVER = localhost; DATABASE = DBT1; UID = scott; PWD = tiger;')
curs = conn.cursor()
curs.execute('select count(edokimp_id)from edokimp')
print curs.fetchall()

脚本引发以下错误

  pyodbc.Error:('IM002','[IM002] [Microsoft] [ODBC驱动程序管理器]未找到数据源名称,未指定默认驱动程序(0)(SQLDriverConnectW)'

由于我是Python的新手,我从错误中意识到,我需要下载pyodbc的IBM DB2驱动程序,因此在Google上广泛搜索但找不到任何。



如果您可以指向我可以下载驱动程序的网站,然后解释我如何配置/加载驱动程序,我将非常感激。



在Java的情况下




  • 驱动程序将以 ojdbc.jar 的形式发送,被复制到 lib 目录,这将在classpath上

  • 更改配置文件

  • 从Java引用DataSource Class



我是Python的新手,所以我非常感激,如果你能让我知道与Python中的一个例子的相应的步骤。 p>

解决方案

你可以得到 PyDB2驱动程序在项目主页。



如果您遇到与官方Python的编译问题, ActivePython 是Python的一个很好的替代分发版Windows。



编辑:如果它要求您使用DB2标头,则需要获取用于ODBC和CLI的IBM Data Server客户端


I downloaded Python 2.7 (python-2.7.1.amd64.msi) and pyodbc, the python extension module for connecting to DB2 database (i.e. pyodbc-2.1.8.win-amd64-py2.7.exe).

I wrote sample script as shown below.

import csv 
import pyodbc 
conn = pyodbc.connectpyodbc.connect('DRIVER={DB2};SERVER=localhost;DATABASE=DBT1;UID=scott;PWD=tiger;')  
curs = conn.cursor() 
curs.execute('select count(edokimp_id) from edokimp') 
print curs.fetchall() 

The script throws following error

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnectW)')

As I am a newbie to Python, I realized from the error that I need to download the IBM DB2 driver for pyodbc and hence searched extensively on Google but couldn't find any.

I would greatly appreciate if you could point me to the site where I can download the driver and later explain me how to configure/load the driver.

In case of Java

  • the driver will be shipped in the form of ojdbc.jar which will be copied to the lib directory which will be on classpath
  • make changes to configuration file
  • reference the DataSource from Java Class

I am newbie to Python so I would greatly appreciate if you could let me know cooresponding steps with an example in Python.

解决方案

You can get the PyDB2 driver on the project homepage.

If you run into compilation issues with the official Python, ActivePython is a good alternate distribution of Python on Windows.

Edit: If it asks you for DB2 headers, you need to get the IBM Data Server Client for ODBC and CLI.

这篇关于pyodbc.Error'IM002'连接到DB2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆