我尝试使用pyodbc创建一个跨数据库验证脚本作为Vertica和Teradata数据库的登录驱动程序。如果我为一个数据库登录运行查询,即vertica或Teradata,则运行正常。当我在Vertica和Teradata中运行脚本时,问题就开始了。 驱动程序每隔两次抛出错误。
(<class 'pyodbc.Error'>, Error('HY000', 'The driver did not supply an error!'), <traceback object at 0x10c18f4d0>)
以下是vertica的连接字符串:
def create_connection_nwk():
conn = pyodbc.connect("DRIVER=Vertica;SERVER=vertica-server;DATABASE=VERTICA-DATABASE;PORT=5433;UID=username;PWD=passphrase")
return conn
以下是Teradata的连接字符串:
def create_connection_redwood():
conn = pyodbc.connect("DRIVER=Teradata;DBCNAME=mydatabase;UID=username;PWD=passphrase;QUIETMODE=YES", autocommit=True,unicode_results=True)
return conn
我使用如下连接,从两个文件源和目标读取查询。
def dqm_newark() :
conn_nwk = create_connection_nwk()
dataframes_newark = []
tgtfile = open('tgtqueries.sql', 'rU').read()
querylist = tgtfile.split(';')
querylist.pop()
for query in querylist :
dataframes_newark.append(pd.read_sql(query, conn_nwk))
close_connection(conn_nwk)
return dataframes_newark,querylist
def dqm_redwood() :
conn_rw = create_connection_redwood()
dataframes_redwood = []
srcfile = open('srcqueries.sql', 'rU').read()
querylist = srcfile.split(';')
querylist.pop()
for query in querylist :
dataframes_redwood.append(pd.read_sql(query, conn_rw))
close_connection(conn_rw)
return dataframes_redwood,querylist
我使用pandas dataframe匹配结果集:
assert_frame_equal(src_dataframes[i], tgt_dataframes[i],check_names=False)
这是追溯:
Traceback (most recent call last): File "DQM.py", line 158, in <module> compare_data() File "DQM.py", line 94, in compare_data
src_dataframes,querylist_redwood = dqm_redwood() File "DQM.py", line 31, in
dqm_redwood conn_rw = create_connection_redwood() File "DQM.py", line 125, in
create_connection_redwood conn = pyodbc.connect("DRIVER=Teradata;DBCNAME=databasename;UID=username;PWD=passwrod;QUIETMODE=YES", autocommit=True,unicode_results=True)
Error: ('HY000', 'The driver did not supply an error!')
我无法弄清楚是什么原因引起了问题。我在这里遗漏了什么?