加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 如何使用pyodbc连接到vertica

发布时间:2020-12-16 23:03:42 所属栏目:Python 来源:网络整理
导读:我已经阅读了关于odbc.ini和 Vertica documentation的 iODBC documentation.我也看到了一个问题 with the same error,但无法按照上一个问题的答案中的建议获得连接字符串. 我目前拥有的: /etc/odbcinst.ini [HPVertica]Description = HP Vertica ODBC Drive
我已经阅读了关于odbc.ini和 Vertica documentation的 iODBC documentation.我也看到了一个问题 with the same error,但无法按照上一个问题的答案中的建议获得连接字符串.

我目前拥有的:

/etc/odbcinst.ini

[HPVertica]
Description = HP Vertica ODBC Driver
Driver = /opt/vertica/lib64/libverticaodbc.so

/etc/odbc.ini

[ODBC Data Sources]
VerticaDB1 = db1 database on HP Vertica

[VerticaDB1]
Description = db1 database on HP Vertica
Driver = HPVertica
Database = db1
Servername = 10.0.0.67
UID = dbadmin
PWD = 
Port = 5433
Locale = en_GB

[ODBC]
Threading = 1

?/ .odbc.ini的

[DEFAULT]

Driver = VerticaDB1

用isql测试

[root@ip-10-0-0-67 /]# echo "select 1;" | isql -v VerticaDB1
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> select 1;
+---------------------+
| ?column?            |
+---------------------+
| 1                   |
+---------------------+
SQLRowCount returns 1
1 rows fetched

odbcinst -j输出:

unixODBC 2.2.14
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

在使用“VerticaDB1”的Python中:

>>> import pyodbc
>>> conn = pyodbc.connect("DRIVER={VerticaDB1};UID={dbadmin};PWD={...}")
Traceback (most recent call last):
  File "",line 1,in 
pyodbc.Error: ('IM002','[IM002] [unixODBC][Driver Manager]Data source name not 
found,and no default driver specified (0) (SQLDriverConnect)')

在使用“HPVertica”的Python中:

>>> import pyodbc
>>> conn = pyodbc.connect("DRIVER={HPVertica};UID={dbadmin};PWD={...}")
Traceback (most recent call last):
  File "",in 
pyodbc.Error: ('HY000','[HY000] [unixODBC][Vertica][ODBC] (10430) Not enough 
information provided to establish a connection to the data source and specified 
to not prompt for more information. (10430) (SQLDriverConnect)')

解决方法

尝试使用DSN进行连接:
conn = pyodbc.connect("DSN=VerticaDB1;UID=dbadmin;PWD=mypassword")

或者,您可以使用DRIVER进行连接,但需要提供更多信息,例如数据库,主机和端口:

conn = pyodbc.connect("DRIVER=HPVertica;SERVER=10.0.0.67;DATABASE=db1;PORT=5433;UID=dbadmin;PWD=mypassword")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读