Уведомления

Группа в Telegram: @pythonsu

#1 Фев. 16, 2021 15:03:40

VIRTOK
Зарегистрирован: 2017-10-23
Сообщения: 77
Репутация: +  0  -
Профиль   Отправить e-mail  

Подключение к базе данных Oracle

Подключение к базе данных Oracle используя следующий код.

 import cx_Oracle
def connect_to_the_oracle_database(host,port,SID,username,password):
   # host = '192.168.0.1'
   # port = 1521
   # SID = 'YOURSIDHERE'
    dsn_tns = cx_Oracle.makedsn(host, port, SID)
#Подключаемся к базе
    myconnection = cx_Oracle.connect(username, password, dsn_tns)
#Cоздаем курсор
    mycursor = myconnection.cursor()
#Выполяем sql-запрос
    mycursor.execute('select * from ver;')
# парсим полученный результат в список кортежей
    result = mycursor.fetchall()
# выводим на экран значения полей
    print(result)
# после выполнения всех нужных нам действий закрываем соединение с базой
    myconnection.close
connect_to_the_oracle_database(host,port,SID,username,password)

Получаю сообщение
 cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 32-bit Oracle Client library: "The specified module could not be found". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
и подключение к БД не получается

Офлайн

#2 Фев. 16, 2021 15:28:46

PEHDOM
Зарегистрирован: 2016-11-28
Сообщения: 2196
Репутация: +  294  -
Профиль   Отправить e-mail  

Подключение к базе данных Oracle

Cannot locate a 32-bit Oracle Client library - не могу найти 32-х битную либу Оракл Клиента.
Очевидно что cx_Oracle только обертка для Oracle Instant Client. Вам нужно его скачать и установить отдельно: https://www.oracle.com/database/technologies/instant-client.html
там по ссылке что вам ошибка выдает https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html все расписано на “щирій англійскій мові”



==============================
Помещайте код в теги:
[code python][/code]
Бериегите свое и чужое время.

Отредактировано PEHDOM (Фев. 16, 2021 19:46:37)

Офлайн

#3 Фев. 16, 2021 20:42:28

VIRTOK
Зарегистрирован: 2017-10-23
Сообщения: 77
Репутация: +  0  -
Профиль   Отправить e-mail  

Подключение к базе данных Oracle

Помогло спасибо
нужно выполнить следующие действия
1. Перейти на страницу
https://www.oracle.com/database/technologies/instant-client/microsoft-windows-32-downloads.html
2. Загрузить https://download.oracle.com/otn_software/nt/instantclient/191000/instantclient-basic-nt-19.10.0.0.0dbru.zip

Далее выполнить следующие действия:

Instant Client Installation for Microsoft Windows 32-bit

See the Instant Client Home Page for more information about Instant Client packages.

Client-server version interoperability is detailed in Doc ID 207303.1. For example, Oracle Call Interface 18.3 and 12.2 can connect to Oracle Database 11.2 or later. Some tools may have other restrictions.

1.Download the appropriate Instant Client packages for your platform. All installations require the Basic or Basic Light package.
2.Unzip the packages into a single directory such as C:\oracle\instantclient_12_2
3.Add this directory to the PATH environment variable. If you have multiple versions of Oracle libraries installed, make sure the new directory occurs first in the path
4.Download and install the correct Visual Studio Redistributable from Microsoft. Instant Client 12.2 requires the Visual Studio 2013 redistributable. Instant Client 12.1 requires the Visual Studio 2010 redistributable.
5.If you intend to co-locate optional Oracle configuration files such as tnsnames.ora, sqlnet.ora, ldap.ora, or oraaccess.xml with Instant Client, then create a subdirectory C:\oracle\instantclient_12_2\network\admin
This is the default Oracle client configuration directory for applications linked with this Instant Client.
Alternatively, Oracle client configuration files can be put in another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.
Start your application.

ODBC users should follow the ODBC Installation Instructions https://www.oracle.com/database/technologies/releasenote-odbc-ic.html

Отредактировано VIRTOK (Фев. 16, 2021 20:43:38)

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version