[英]How to connect oracle database with python pypyodbc
I am trying to connect an oracle database from my python code using pypyodbc
: 我试图使用pypyodbc
从我的python代码连接一个oracle数据库:
conn_string = "driver={Oracle in OraClient11g_home1}; server='example.oneco.com:1521'; database='tabto'; uid='myuid'; pwd='mypwd'"
conn = pypyodbc.connect(conn_string)
I got error message: 我收到错误消息:
Error: (u'HY000', u'[HY000] [Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error\\n') 错误:(u'HY000',u'[HY000] [Oracle] [ODBC] [Ora] ORA-12560:TNS:协议适配器错误\\ n')
Following is the connection string found in my tnsnames.ora
file. 以下是在我的tnsnames.ora
文件中找到的连接字符串。 Please tell me what is the right way to use pypyodbc
. 请告诉我使用pypyodbc
的正确方法是什么。
tabto, tabto.world, tabto.oracleoutsourcing.com, tabto.oneco.com =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = example.oneco.com)
(PORT = 1521)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = tabto_dcu)
)
)
The key is link python code to tnsname.ora by defining dbq
parameter. 关键是通过定义dbq
参数将python代码链接到tnsname.ora。 So change the code to the following worked. 因此,将代码更改为以下工作方式。
conn_string = "driver={Oracle in OraClient11g_home1}; dbq='tabto'; uid='myuid'; pwd='mypwd'"
conn = pypyodbc.connect(conn_string)
conn = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER=example.oneco.com:1521;DATABASE=tabto;UID=youruid;PWD=password')
try it without quotes(') of your code in the middle... 尝试在中间不加引号的情况下...
check too pyodbc wiki: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Windows 也检查pyodbc Wiki: https : //github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Windows
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.