python:使用Oracle的wallet / tnsnames连接到Oracle数据库 [英] python: connecting to an Oracle database using Oracle's wallet/tnsnames

查看:261
本文介绍了python:使用Oracle的wallet / tnsnames连接到Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我可以这样连接到Oracle数据库:

So I can connect to an Oracle database as such:

import cx_Oracle as ora
dsnStr = ora.makedsn(host="ABC.COM", port="ABC_PORT", sid="ABC")
con = ora.connect(user="ABC_USER", password="ABC_PASSWORD", dsn=dsnStr)
print(con.version)
con.close()

这非常有效很好,但是我想使用 Oracle钱包 / tnsnames / database.properties进行连接(我来自Java世界)。到目前为止,找不到有关如何实现该目标的任何信息。另外,如何根据这些 Oracle钱包 / cx_Oracle > tnsnames / database.properties 相应的文件。

and this works very well, but I would like to connect using the Oracle wallet/tnsnames/database.properties (I'm coming from the Java world). Couldn't find anything so far on how to achieve that. Also, how can I "configure" cx_Oracle in terms of the paths to these Oracle wallet/tnsnames/database.properties respective files.

推荐答案

cx_Oracle使用与SQL Plus相同的技术来连接数据库。因此,如果您发现这样做更容易,则可以先使用SQL Plus进行测试。

cx_Oracle uses the same techniques to connect to the database as SQLPlus. So you can test with SQLPlus first if you find that easier to do.

为此,您需要创建一个sqlnet.ora配置。文件。这样,您可以将这些参数设置为钱包文件的位置。如果在默认位置找不到环境变量TNS_ADMIN,则可以使用它来指定此配置文件和其他配置文件(例如tnsnames.ora)的位置。有关更多信息,请参见文档

In order to do this you will need to create a sqlnet.ora configuration file. This allows you to set such parameters as the location of the wallet file. The environment variable TNS_ADMIN can be used to specify the location of this and other configuration files (like tnsnames.ora) if it isn't found in the default location. See the documentation for more information.

这篇关于python:使用Oracle的wallet / tnsnames连接到Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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