Python应用程序连接到InterSystemsIRIS数据库 - 使用 pyodbc
此篇文章给大家介绍一个使用pyodbc连接到 InterSystems IRIS数据库的示例,详情如下:
InterSystems IRIS 安装在Redhat 操作系统中,使用pyodbc在Mac操作系统中连接到Redhat 操作系统中InterSystems IRIS数据库。
- 下载测试代码
- 使用vscode打开测试代码,并在Solutions文件夹下安装pyodbc
pip install pyodbc
- 在Mac操作系统中安装ODBC驱动
brew update brew install unixodbc
- 安装后,查看Mac操作系统中的odbcinst.ini文件,此时odbcinst.ini文件应该是空的。
- Mac操作系统中/usr/local/bin下使用下列命令注册驱动 或者 配置DSN
- 注册ODBC驱动
odbcinst -i -d -f pyodbc_wheel/mac/odbcinst.ini
- 配置本地DSN
pyodbc_wheel/mac/odbcinst.iniodbcinst -i -s -h -f odbc.ini_unixODBCtemplate
- 配置系统DSN
odbcinst -i -s -l -f pyodbc_wheel/mac/odbcinst.ini
- 执行后,查看Mac操作系统中的odbcinst.ini文件,此时odbcinst.ini文件应该是空的, 安装如下信息更改odbcinst.ini文件。
[InterSystems ODBC] Description=InterSystems ODBC Driver=pyodbc_wheel/mac/libirisodbc35.so Setup=pyodbc_wheel/mac/libirisodbc35.so UsageCount=1
- 将connection.config连接配置文件里面的内容改成Redhat 操作系统中InterSystems IRIS的连接信息。
ip: 192.168.157.XX port: 51773 namespace: USER username: user password: pwd
- 运行pyodbcplaystocksTask1.py 文件。会显示“Connected to InterSystems IRIS”,表示成功连接到InterSystems IRIS 。