Ошибка oracle initializing oci environment handle

I have a problem with TOAD for Oracle 9.1 running on Windows 7 32-bit, described as follows:

I have Oracle OraClient10g 10.0.2 installed on my PC, and I need to use Toad 9.1. When I try to log into a server, I specify the database via TNS, I type the user name and password, but I get a message with the following error:

Can’t initialize OCI. Error -1

Googling around I got several options which include: check that the ORACLE_HOME environment variable is set right, run TOAD as administrator, check that the user name and password are correct, install Oracle and TOAD for 32-bit system… I have checked all those options but I am still getting the error.

There is, however, a detail I should mention: In my start menu, there are two Oracle Homes (Home1 and Home2). Home 2 points to an empty folder because I reinstalled Oracle during my attempts to solve the problem, and the short cut is still in my start menu. I don’t think this is important, though, because ORACLE_HOME is pointing to the right home.

I really need help with this. I need to solve this error and log in using TOAD.

I have a problem with TOAD for Oracle 9.1 running on Windows 7 32-bit, described as follows:

I have Oracle OraClient10g 10.0.2 installed on my PC, and I need to use Toad 9.1. When I try to log into a server, I specify the database via TNS, I type the user name and password, but I get a message with the following error:

Can’t initialize OCI. Error -1

Googling around I got several options which include: check that the ORACLE_HOME environment variable is set right, run TOAD as administrator, check that the user name and password are correct, install Oracle and TOAD for 32-bit system… I have checked all those options but I am still getting the error.

There is, however, a detail I should mention: In my start menu, there are two Oracle Homes (Home1 and Home2). Home 2 points to an empty folder because I reinstalled Oracle during my attempts to solve the problem, and the short cut is still in my start menu. I don’t think this is important, though, because ORACLE_HOME is pointing to the right home.

I really need help with this. I need to solve this error and log in using TOAD.

У меня проблема с жабой для Oracle 9.1, работающей на Windows 7 32-бит, описывается следующим образом:

на моем ПК установлен Oracle OraClient10g 10.0.2, и мне нужно использовать Toad 9.1. Когда я пытаюсь войти в сервер, я указываю базу данных через TNS, я ввожу имя пользователя и пароль, но я получаю сообщение со следующей ошибкой:

не удается инициализировать OCI. Ошибка -1

Googling around у меня есть несколько вариантов, которые включают в себя: проверьте, что ORACLE_HOME переменная среды установлена правильно, запустите TOAD как администратор, проверьте правильность имени пользователя и пароля, установите Oracle и TOAD для 32-битной системы… Я проверил все эти параметры, но я все еще получаю ошибку.

есть, однако, деталь, которую я должен упомянуть: в моем меню «Пуск» есть два дома Oracle (Home1 и Home2). Home 2 указывает на пустую папку, потому что я переустановил Oracle во время моих попыток решить проблему, и короткий путь все еще находится в моем начале меню. Я не думаю, что это важно, потому что ORACLE_HOME указывает на правильный дом.

Мне действительно нужна помощь с этим. Мне нужно решить эту ошибку и войти в систему с помощью TOAD.

10 ответов


Я открыл жабу с правами администратора (Right click -> Run as Administrator). Проблема решена.

Спасибо большое!


для меня эта проблема была вызвана меня задание ORACLE_HOME переменная среды windows (постоянно). Я установил это, пытаясь получить "emctl" на работу.

после удаления жаба работала нормально.


удаление ORACLE_HOME из переменных среды (системы) работало для меня.
Жаба теперь работает нормально.

2

автор: Jose Pedro Almeida


проблема решена: я изменил переменные среды, в том числе в реестре Windows, и жаба показала Oracle home красным цветом в меню TNS. Я поставил переменные среды так, как они могли бы соединиться с Toad… Странно, но сейчас это работает.


в моем случае я получал ту же ошибку с клиентом Oracle 10g, Toad 10 Commercial, установленным на моем ПК с Windows 7. Я пытался получить доступ к серверу Oracle 10G с моего ПК.
Я получал эту ошибку, пытаясь получить доступ от Toad.

наконец, решение, которое я нашел, было :
Я открыл toad с правами администратора (щелкните правой кнопкой мыши -> Запуск от имени администратора). Проблема решена.


Не уверен, что другие вещи установлена на вашем ноутбуке / рабочий стол.
Но у меня была жаба 11.6, а затем я установил другой продукт oracle realted, который создал другие дома. Ниже предложения сделали не работать на меня :

  • Regedit — > программное обеспечение — > Wow6432Node — > Oracle — > KEY_ORA_WF_NK имеет правильный ORACLE_HOME
  • переменная среды ORACLE_HOME в локальной системе также имеет то же самое.

вместо этого я попытался ниже, и это сработало для меня и вот еще одно предложение:

  • когда вы открываете жабу, вам обычно предлагается, какую БД подключить, и есть возможность выбрать («…») рядом со списком установленных домов, как только вы нажмете там, он укажет ошибку (при нажатии кнопки), поэтому я попробовал это и что-то жаловался на то, что путь не установлен, как только я исправил путь, и он работал. После этого жаба открывается нормально (т. е. не нужно использовать опцию Run As Admin).

BTW: Прежде чем пытаться исправить выше , я попытался запустить как администратор, и это сработало.

надеюсь, это поможет, если не извините меня.

1

автор: BB-on-StackOverflow


великолепно!!

он работает после того, как эти две вещи синхронизированы:

  1. Regedit -> Softerware -> Wow6432Node -> Oracle -> KEY_ORA_WF_NK has correct ORACLE_HOME
  2. переменные среды ORACLE_HOME в локальной системе также есть то же самое.

Я получил эту ошибку «OCI_INVALID_HANDLE» во время подключения к удаленной базе данных после удаления одной из моих избыточных установок клиента Oracle 12c DB. ОС моей машины-Windows 10 Enterprise. Проблема устранена путем добавления ключа ORACLE_HOME в путь к системной среде.

поскольку у меня нет ключа ORACLE_HOME в моем пути к системной среде, я создаю его, выполнив следующие шаги:

  1. щелкните правой кнопкой мыши на «этот ПК»
  2. клик «Свойства» — > » расширенная система
    настройки»
  3. нажимаем «переменные среды…»в вкладке «Дополнительно»
  4. Нажать «Новая…»в разделе» системные переменные»
  5. поместите «ORACLE_HOME» в
    Поле «имя переменной» и укажите путь установки oracle db
    клиент (ex: C:oracleproduct12.1.0client_1) в разделе » значение переменной»
    поле
  6. Нажмите «Ok».

enter image description here


возможно, у вас будут установлены Oracle и Oracle Express, поэтому любые переменные среды конфигурации могут быть изменены, если это так, вход прямой, а не TNSNAME и настройки будут localhost 1521 вариант serviceName: xe, оставляя подключение с использованием всегда клиента oracle, например Instant Client — 11.2


Windows 7 блокирует диск C вот почему работает как администратор.


@jerome-peng

I use the root user to install

# yum install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm 
# yum install oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm 

I use the report user which is the owner of the PG server.
I can use sqlplus to login to oracle server as user report.

here is my error:

report=> SELECT oracle_diag('server_ora_99');
ERROR:  error connecting to Oracle: OCIEnvCreate failed to create environment handle
DETAIL:  
report=> select oracle_diag();
                                             oracle_diag                                              
------------------------------------------------------------------------------------------------------
 oracle_fdw 2.0.0, PostgreSQL 9.5.12, Oracle client 11.2.0.4.0, ORACLE_HOME=/opt/oracle/instantclient
(1 row)

@laurenz

Oh no, the dreaded «OCIEnvCreate failed to create environment handle».

It means that something is wrong with your Oracle setup. Oracle does not tell you what. Often some environment variable.

As a first step, you can check all Oracle related environment variables you have set in the shell where sqlplus works. Perhaps some of them are not set in the environment of the PostgreSQL server.

Which naming method do you use to connect to Oracle? Can I see the connection string?

You might want to look through all the past issues that mention OCIEnvCreate, maybe you get a clue there.

Sometimes using strace to trace the PostgreSQL backend is helpful; it might show you where Oracle goes wrong.

@jerome-peng

thanks a lot.

my problem is solved by reboot the server.

below is my environment variable.

LD_LIBRARY_PATH=/opt/oracle/instantclient:/home/jerome/work/pgsql/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
OCI_INC_DIR=/opt/oracle/instantclient/sdk/include
OCI_LIB_DIR=/opt/oracle/instantclient
ORACLE_HOME=/opt/oracle/instantclient

@laurenz

Glad to hear, thanks for the feedback.

I don’t think it can have been these environment variables, so this incident can be added to the sad collection of unclear OCIEnvCreate problems …

@kumakichi

I came cross the same problem, and solved, with ubuntu 18.04.1(docker)

paste the steps here, may help somebody with the same problem:

  1. find out how to start server
  • start server with service postgresql start or /etc/init.d/postgresql start
  • find the command ps ax | grep postgres, you will get something like

/usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf

  1. prepare
  • stop server firstly
    service postgresql stop
  • su(root user is not allowed to start server by default)
    su - postgres
  1. add environment variables
export ORACLE_HOME=/opt/oracle/instantclient_12_2

export LD_LIBRARY_PATH=$ORACLE_HOME:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
  1. start server
    run command got from step 1 , here, it is:
    /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf

then, connect server again, you will find this problem solved.

@laurenz

For the record: On Linux, it is better to put Oracle on the library path by adding the directory to /etc/ld.so.conf and running ldconfig.

Repository owner

locked as resolved and limited conversation to collaborators

May 8, 2019

Stefan

unread,

Sep 22, 2018, 3:16:43 PM9/22/18

to mapi…@googlegroups.com

Hi there,

i’m experiencing a strange Problem here.

I’ve developed an MS-Access-application in VBA that starts MiPro in the Background via 

Set objMapInfo = CreateObject(«Mapinfo.Application.x64»)

Now i’ve three Computers running that app, but it does so only on one machine, on the other two i get this error 

OCI_Error_Message.png

Oracle-Error: Allocating OCI Environment handle.

Searching the Internet i found a short article on the PB Website About that Problem with MiPro 32-Bit, explaining that the Problem may be solved by reinstalling the Oracle Client matching the MiPro-Version. In my case that would mean: reinstall the whole Oracle DB, — no way!

I checked the machines for differences.

All running Windows 10 Pro 64-Bit / 1803 / German / MiPro 15.03 DE / MiPro 17.01 Advanced / Oracle 12.2 32-Bit Instant Client / Oracle 12C Enterprise DB / same MS-Office Version.

Setup is the same, 32-bit MiPro can Access the Oracle db as well.

In the path on all machines the 64-bit Oracle bin-path Comes before the 32-bit instant Client path. The Oracle global variables are the same.

On all three machines it’s no Problem to load a spatial layer from the local Oracle instance in MiPro 17.01 when started regulary via Windows startmenu, but when i issue the vba-codeline above, on two machine i get that error message instantly, on one of the machine everything runs as expected.

Attached you will find an MS-Access Database demonstrating the strangeness of that problem. To make it work you will have to edit the query- and connection-parameters in the function «EO_Get_Value_List» in Module1. The function generates a delimited list of  the string values of an oracle table column.

If you managed to make that work, you can click on the button «Get Oracle Values» on the main form, that will fill the oracle-values listbox.

So, if you now close the database and open it again, you can try to click on the buton «Start MiPro64», that will try to create a MiPro object in the background.

In my case i get a «General protection fault» some 30 seconds later, and a nice MiPro.dmp file in my temp-Directory.

BUT

if i close the database and open it up again, and click first on the button «Get Oracle Values» and click afterwards on the button «Start MiPro64» the above errormessage appears instantely, and no oralce connection with this instance of MiPro is possible.

After many Hours of searching i’m lost, and any thoughts are highly welcome.

Thanks and have a nice Weekend

Stefan

Eric Blasenheim

unread,

Sep 23, 2018, 9:26:36 PM9/23/18

to MapInfo-L

Stefan,

The key is that you need a 64-bit Oracle OCI client on every machine where Pro (or any other 64-bit client) is installed for us to talk to Oracle.  Those client dlls can just be the «instant client» but they need to be there and be accessible (via the system path) for MapInfo Pro to load.  This is not a MapInfo limitation, this is the way 32 and  64 bit machine software works on all systems.

It seems you have the Oracle database on the same machine but that should not matter other than the fact that the 64-bit client dlls may already be there. 

But what you need to do is:

Make sure the 64-bit version of oci.dll and its dependent dlls (what comes with the instant or full client) are on the machine. 

Make sure that location is on the system path when MI Pro is running. Since you are launching Pro via COM/VBA this may mean it needs to be on the true system level path as we are being launched by the system and not directly your VBA program.  You can see what path an executable truly has at run time via tools like Windows Process Explorer. 

Note that some people think there is an issue with having the 32 and 64 bit versions on the path. In general, this is not true. When MI Pro tries to load OCI via the Windows API, the 64-bit OS completely ignores any 32 bit DLLs that happen to have the name OCI.DLL.  So the order on the path does not matter.  (if you try programmatically to point a 64-bit program to a 32 bit dll with an explicit path, Windows tells you this is not an executable).

When the loading of a particular Oracle table uses a SSID whose description is in the tnsnames.ora file, for OCI to locate those and know what they mean., their code uses the TNS_ADMIN environment variable to locate that file.  So it should be set to the location of  the tnsnames.ora file. 

But really it is just making sure Pro can load the 64-bit OCI.DLL 

I hope this helps.

Eric Blasenheim

Pitney Bowes Software.

On Saturday, September 22, 2018 at 8:16:43 AM UTC-4, Stefan wrote:

Hi there,

i’m experiencing a strange Problem here.

I’ve developed an MS-Access-application in VBA that starts MiPro in the Background via 

Set objMapInfo = CreateObject(«Mapinfo.Application.x64»)

Now i’ve three Computers running that app, but it does so only on one machine, on the other two i get this error 

OCI_Error_Message.png

Oracle-Error: Allocating OCI Environment handle.

Searching the Internet i found a short article on the PB Website About that Problem with MiPro 32-Bit, explaining that the Problem may be solved by reinstalling the Oracle Client matching the MiPro-Version. In my case that would mean: reinstall the whole Oracle DB, — no way!

I checked the machines for differences.

All running Windows 10 Pro 64-Bit / 1803 / German / MiPro 15.03 DE / MiPro 17.01 Advanced / Oracle 12.2 32-Bit Instant Client / Oracle 12C Enterprise DB / same MS-Office Version.

Setup is the same, 32-bit MiPro can Access the Oracle db as well.

In the path on all machines the 64-bit Oracle bin-path Comes before the 32-bit instant Client path. The Oracle global variables are the same.

On all three machines it’s no Problem to load a spatial layer from the local Oracle instance in MiPro 17.01 when started regulary via Windows startmenu, but when i issue the vba-codeline above, on two machine i get that error message instantly, on one of the machine everything runs as expected.

The only difference i was able to find is, that the machine without Errors is running Oracle DB 12.1 while the other failing machines are running 12.2.

I would think that it’s quite unprobable that this is the source of this Problem, — but what else?

Stefan

unread,

Sep 24, 2018, 10:38:30 AM9/24/18

to MapInfo-L

Good morning Eric,

thanks for this fast reply.

But as i wrote: On all machines i can launch MiPro from the start menu and load Oracle layers just fine. On all machines a full Oracle Enterprise 64-bit database installation is present and the bin directory in the path, — as well as the 32-bit instant client directory.

Loading Oracle spatial layers from 32-bit MiPro 15 on the same machines works as well.

So this cannot be the issue, — from my point of view.

The strange thing is, that starting MiPro 64-Bit via COM/VBA does work on these two machines, but not if you made an oracle 32-bit connection from within ms-access before (as explained above).

You mentioned process explorer. i used that yesterday to see, what’s going on there and found, that when i get that error message, the access to the oci.dll looks different, — but i’m not expert enough to know, if that means anything.

Everytime, and i tested that many times, — that error comes up, MiPro doesn’t actually read the oci.dll (the marked red part), — as it does, when successfully started.

Successfull load:

OCI_access_successfull.png

Unsuccessfull load attempt:

OCI_access_unsuccessfull.png

And as you can see: MiPro can find the correct oci.dll.

… and on the machine running version 12.1 of Oracle enterprise, even that lauch works.

Thanks in advance for any further help

and

Best regards

Stefan

Stefan

unread,

Sep 25, 2018, 4:53:55 PM9/25/18

to MapInfo-L

Found the solution by myself:

Everything works as expected, if you set on ORACLE_HOME-Variable to point at your 64-Bit Installation.

It stays a bit strange, that running MiPro from windows start menu works flawless with oracle connections but starting via COM doesn’t.

Anyway, it works now, — great.

Stefan

Sidhu Sidvester

unread,

Apr 21, 2020, 8:41:53 AM4/21/20

to MapInfo-L

Hi Stefan,

Good Day!

Could you please share the screenshot of the below ORACEL_HOME Variable .am also facing the same issue.

-Sidhu

After normal installation of Oracle Client or Oracle DB, open Toad, click Connet, and report Can’t initialize oci. error-1.

Solutions:
(1) Environment variable: Simply set path and add the path of Oracle Client to path
(2) Network /admin: add tnsnames.ora and find one or copy one
(3) The key step: Copy Toad’s entire folder to the Oracle Client path

Read More:

Hi,
I am using PL/SQL Developer version 11 on Windows 10 64bit and I keep getting the following error message:

«Initialization error
Could not initialize
C:Oracleproductinstantclient_12_1oci.dll

OCIDLL forced to C:Oracleproductinstantclient_12_1oci.dll
LoadLibrary(C:Oracleproductinstantclient_12_1oci.dll)
returned 0
«

. I have installed the following versions of the Oracle Client:
— Instant Client 11.3 (32bit)
— Instant Client 12.1 (32bit)
— Oracle client 11.2 (32bit)
I configure the IDE under tools/preferences to set the Oracle home and OCI library to point to the above client.
I also set the TNS_ADMiN environment variable.
All of the above to no avail. Please help.

Support Info below:

PL/SQL Developer
Version 11.0.4.1788 (64 bit)
02.100339 — 100 user license
Service Contract: 4/1/2016
Windows 10 Build 10586

Physical memory : 16,696,464 kB (13,123,296 available)
Paging file : 19,186,832 kB (15,484,372 available)
Virtual memory : 137,438,953,344 kB (137,438,645,220 available)

Parameters
C:Program FilesPLSQL Developerplsqldev.exe

Preferences
Session mode: Multi
OCI Library: C:Oracleproductinstantclient_12_1oci.dll
Use OCI7: False
Allow Multiple Connections: True

Preference Files
C:UsersRolandAppDataRoamingPLSQL DeveloperPreferencesdefaultDefault.ini
C:UsersRolandAppDataRoamingPLSQL DeveloperPreferencesRolanddefault.ini

License File
C:UsersRolandAppDataRoamingPLSQL Developeraalf.dat

Debug file
C:UsersRolandAppDataRoamingPLSQL DeveloperPlSqlDev.elf

Plug-Ins
*Active Query Builder (C:Program FilesPLSQL DeveloperPlugInsActiveQueryBuilder.dll)
*PL/SQL Documentation (plsqldoc) (C:Program FilesPLSQL DeveloperPlugInsplsqldoc.dll)
*Red Gate Deployment Plug-In (C:Program FilesPLSQL DeveloperPlugInsRedGate.dll)
(* is Active)

Aliases

Homes

DLLs
C:Oracleproductinstantclient_12_1oci.dll

TNS File

Using
Home:
DLL: C:Oracleproductinstantclient_12_1oci.dll
OCI: not initialized

Monitor
PixelsPerInch = 120

Id = 0
Primary = True
Handle = 65537
Left = 0
Top = 0
Width = 1920
Height = 1080

MainFormOnTaskbar = False

I was able to install oracle_fdw, between Postgresql and Oracle. I’ve installed Oracle Instant client on the Linux machine.

On the Postgresql server, I’ve installed Oracle Client, and configured it to connect to the Oracle database. sqlplus name/password@ORCL is working on the command line.

My tnsnames.ora is:

ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.148.51.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )

I’ve copied tnsnames.ora to $ORACLE_HOME/network/admin/tnsnames.ora

My environment variables are:

export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=$ORACLE_HOME/bin:/usr/pgsql-9.1/bin/:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

On the postgresql init script, /etc/init.d/postgresql, I’ve also set the variables:

export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin

I’ve also changed the file /etc/ld.so.conf.d/postgresql-9.1-libs.conf

$ cat /etc/ld.so.conf.d/postgresql-9.1-libs.conf
/usr/pgsql-9.1/lib/
/usr/lib/oracle/11.2/client64/lib/

$ sudo ldconfig
$ sudo /etc/init.d/postgresql restart

To use oracle_fdw, I used:

$ psql ide

ide=# CREATE EXTENSION oracle_fdw;
ide=# CREATE SERVER medidata FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver '//192.148.51.2:1521/ORCL');

I already have a small table in Oracle called ‘zonas’. To use ‘zonas’ in Postgresql, I’ve done:

ide=# CREATE FOREIGN TABLE zonas (
    COD_ZONA text,
    ZONA    text,
    RESPONSAVEL       numeric
    ) 
SERVER medidata
OPTIONS (table 'zonas');

ide=# select * from zonas;
 cod_zona | zona | responsavel 
----------+------+-------------
 2        | 2    |           2
 1        | 1    |           1
(2 rows)

I hope it helps.

Содержание

  1. 2 OCI Programming Basics
  2. Overview of OCI Programming
  3. OCI Program Structure
  4. Figure 2-1 Basic OCI Program Flow
  5. Figure 2-2 Multiple Environments Within an OCI Process
  6. OCI Data Structures
  7. Handles
  8. Allocating and Freeing Handles
  9. Figure 2-3 Hierarchy of Handles
  10. Environment Handle
  11. Error Handle
  12. Service Context and Associated Handles
  13. Figure 2-4 Components of a Service Context
  14. Statement Handle, Bind Handle, and Define Handle
  15. Figure 2-5 Statement Handles
  16. Describe Handle
  17. Complex Object Retrieval Handle
  18. Thread Handle
  19. Subscription Handle
  20. Direct Path Handles
  21. Figure 2-6 Direct Path Handles
  22. Process Handle
  23. Connection Pool Handle
  24. Handle Attributes
  25. User Memory Allocation
  26. Descriptors
  27. Snapshot Descriptor
  28. LOB/FILE Datatype Locator
  29. Parameter Descriptor
  30. ROWID Descriptor
  31. Datetime and Interval Descriptors
  32. Complex Object Descriptor
  33. Advanced Queuing Descriptors
  34. LDAP-based Publish-Subscribe Notification
  35. User Memory Allocation
  36. OCI Programming Steps
  37. OCI Environment Initialization
  38. Creating the OCI Environment
  39. Shared Data Mode
  40. Using OCI Functions
  41. Using Environment Variables
  42. Allocating Handles and Descriptors
  43. Application Initialization, Connection, and Session Creation
  44. Option 1: Single User, Single Connection
  45. Option 2: Multiple Sessions or Connections
  46. Processing SQL Statements
  47. Commit or Rollback
  48. Terminating the Application
  49. Error Handling
  50. Return and Error Codes for Truncation and Null Data

2
OCI Programming Basics

This chapter introduces you to the basic concepts involved in programming with the OCI. This chapter covers the following topics:

Overview of OCI Programming

This chapter provides an introduction to the concepts and procedures involved in developing an OCI application. After reading this chapter, you should have most of the tools necessary to understand and create a basic OCI application.

This chapter is broken down into the following major sections:

  • OCI Program Structure — covers the basic overall structure of an OCI application, including the major steps involved in creating one.
  • OCI Data Structures — discusses handles, and descriptors.
  • OCI Programming Steps — discusses in detail each of the steps involved in coding an OCI application.
  • Error Handling — covers error handling in OCI applications.
  • Additional Coding Guidelines — provides useful information to keep in mind when coding an OCI application.
  • Nonblocking Mode — this section covers the use of nonblocking mode to connect to an Oracle database server.
  • Using PL/SQL in an OCI Program — discusses some important points to keep in mind when working with PL/SQL in an OCI application.

New users should pay particular attention to the information presented in this chapter, because it forms the basis for the rest of the material presented in this guide. The information in this chapter is supplemented by information in later chapters.

See Also:

  • For a discussion of the OCI functions that apply to a multilingual environment, see the Oracle9i Database Globalization Support Guide
  • For a discussion of the OCI functions that apply to cartridge services, see the Oracle9i Data Cartridge Developer’s Guide.

OCI Program Structure

The general goal of an OCI application is to operate on behalf of multiple users. In an n-tiered configuration, multiple users are sending HTTP requests to the client application. The client application may need to perform some data operations that include exchanging data and performing data processing.

The OCI uses the following basic program structure:

  1. Initialize the OCI programming environment and threads.
  2. Allocate necessary handles, and establish server connections and user sessions.
  3. Exchange data with the database server by executing SQL statements on the server, and perform necessary application data processing.
  4. Reexecute prepared statements, or prepare a new statement for execution.
  5. Terminate user sessions and server connections.
  6. Free handles.

Figure 2-1, «Basic OCI Program Flow» illustrates the flow of steps in an OCI application. Each step is described in more detail in the section «OCI Programming Steps» .

Figure 2-1 Basic OCI Program Flow

Keep in mind that the diagram and the list of steps present a simple generalization of OCI programming steps. Variations are possible, depending on the functionality of the program. OCI applications that include more sophisticated functionality, such as managing multiple sessions and transactions and using objects, require additional steps.

All OCI function calls are executed in the context of an environment. There can be multiple environments within an OCI process, as illustrated in Figure 2-2, «Multiple Environments Within an OCI Process». If an environment requires any process-level initialization then it is performed automatically.

In previous releases, a separate explicit process-level initialization was required. This requirement has been simplified and no explicit process-level initialization is required.

Figure 2-2 Multiple Environments Within an OCI Process

It is possible to have more than one active connection and statement in an OCI application.

For information about accessing and manipulating objects, see Chapter 10, «OCI Object-Relational Programming» and the chapters that follow it

OCI Data Structures

Handles and descriptors are opaque data structures which are defined in OCI applications and may be allocated directly, through specific allocate calls, or may be implicitly allocated by OCI functions.

Programmers who have previously written 7.x OCI applications need to become familiar with these new data structures which are used by most OCI calls

Handles and descriptors store information pertaining to data, connections, or application behavior. Handles are defined in more detail in the following section. Descriptors are discussed in the section «Descriptors» .

Handles

Almost all OCI calls include in their parameter list one or more handles. A handle is an opaque pointer to a storage area allocated by the OCI library. You use a handle to store context or connection information, (for example, an environment or service context handle), or it may store information about OCI functions or data (for example, an error or describe handle). Handles can make programming easier, because the library, rather than the application, maintains this data.

Most OCI applications need to access the information stored in handles. The get and set attribute OCI calls, OCIAttrGet() and OCIAttrSet() , access this information.

For more information about using handle attributes, see the section «Handle Attributes»

The following table lists the handles defined for the OCI. For each handle type, the C datatype and handle type constant used to identify the handle type in OCI calls are listed.

Table 2-1 OCI Handle Types

OCI environment handle

OCI error handle

OCI service context handle

OCI statement handle

OCI bind handle

OCI define handle

OCI describe handle

OCI server handle

OCI user session handle

OCI authentication information handle

OCI connection pool handle

OCI session pool handle

OCI transaction handle

OCI complex object retrieval (COR) handle

OCI thread handle

OCI subscription handle

OCI direct path context handle

OCI direct path function context handle

OCI direct path column array handle

OCI direct path stream handle

OCI process handle

Allocating and Freeing Handles

Your application allocates all handles (except the bind, define, and thread handles) with respect to particular environment handle. You pass the environment handle as one of the parameters to the handle allocation call. The allocated handles is then specific to that particular environment.

The bind and define handles are allocated with respect to a statement handle, and contain information about the statement represented by that handle.

The bind and define handles are implicitly allocated by the OCI library, and do not require user allocation.

Figure 2-3, «Hierarchy of Handles» illustrates the relationship between the various types of handles.

All user-allocated handles are allocated using the OCI handle allocation call, OCIHandleAlloc() .

The environment handle is allocated and initialized with a call to OCIEnvCreate() , which is required by all OCI applications.

The thread handle is allocated with the OCIThreadHndInit() call.

An application must free all handles when they are no longer needed. The OCIHandleFree() function frees handles.

When a parent handle is freed, all child handles associated with it are also freed, and can no longer be used. For example, when a statement handle is freed, any bind and define handles associated with it are also freed.

Figure 2-3 Hierarchy of Handles

Handles lessen the need for global variables. Handles also make error reporting easier. An error handle is used to return errors and diagnostic information.

For sample code demonstrating the allocation and use of OCI handles, see the example programs listed in Appendix B, «OCI Demonstration Programs»

The various handle types are described in more detail in the following sections.

Environment Handle

The environment handle defines a context in which all OCI functions are invoked. Each environment handle contains a memory cache, which allows for fast memory access. All memory allocation under the environment handle is done from this cache. Access to the cache is serialized if multiple threads try to allocate memory under the same environment handle. When multiple threads share a single environment handle, they may block on access to the cache.

The environment handle is passed as the parent parameter to the OCIHandleAlloc() call to allocate all other handle types. Bind and define handles are allocated implicitly.

Error Handle

The error handle is passed as a parameter to most OCI calls. The error handle maintains information about errors that occur during an OCI operation. If an error occurs in a call, the error handle can be passed to OCIErrorGet() to obtain additional information about the error that occurred.

Allocating the error handle is one of the first steps in an OCI application because most OCI calls require an error handle as one of its parameters.

Service Context and Associated Handles

A service context handle defines attributes that determine the operational context for OCI calls to a server. The service context contains three handles as its attributes, that represent a server connection, a user session, and a transaction. These attributes are illustrated in Figure 2-4, «Components of a Service Context»:

Figure 2-4 Components of a Service Context

  • A server handle identifies a connection to a database. It translates into a physical connection in a connection-oriented transport mechanism.
  • A user session handle defines a user’s roles and privileges (also known as the user’s security domain), and the operational context on which the calls execute.
  • A transaction handle defines the transaction in which the SQL operations are performed. The transaction context includes user session state information, including the fetch state and package instantiation, if any.

Breaking the service context down in this way provides scalability and enables programmers to create sophisticated three-tiered applications and transaction processing (TP) monitors to execute requests on behalf of multiple users on multiple application servers and different transaction contexts.

You must allocate and initialize the service context handle with OCIHandleAlloc() or OCILogon() before you can use it. The service context handle is allocated explicitly by OCIHandleAlloc() . It can be initialized using OCIAttrSet() with the server, session, and transaction handle. If the service context handle is allocated implicitly using OCILogon() , it is already initialized.

Applications maintaining only a single user session for each database connection at any time can call OCILogon() to get an initialized service context handle.

In applications requiring more complex session management, the service context must be explicitly allocated, and the server handle and user session handle must be explicitly set into the service context. OCIServerAttach() and OCISessionBegin() , calls initialize the server and user session handle respectively.

An application will only define a transaction explicitly if it is a global transaction or there are multiple transactions active for sessions. It will be able to work correctly with the implicit transaction created automatically by OCI when the application makes changes to the database.

Description C Type Handle Type

See Also:

  • For more information about transactions, see the section «OCI Support for Transactions»
  • For more information about establishing a server connection and user session, see the sections «OCI Environment Initialization» , and «Password and Session Management»

Statement Handle, Bind Handle, and Define Handle

A statement handle is the context that identifies a SQL or PL/SQL statement and its associated attributes.

Figure 2-5 Statement Handles

Information about input and output bind variables is stored in bind handles. The OCI library allocates a bind handle for each placeholder bound with the OCIBindByName() or OCIBindByPos() function. The user does not need to allocate bind handles. They are implicitly allocated by the bind call.

Fetched data returned by a query (select statement) is converted and retrieved according to the specifications of the define handles. The OCI library allocates a define handle for each output variable defined with OCIDefineByPos() . The user does not need to allocate define handles. They are implicitly allocated by the define call.

Bind and define handles are freed when the statement handle is freed or when a new statement is prepared on the statement handle.

Statement context data, the data associated with a statement handle, can be shared.

For information about OCI shared mode, see «Shared Data Mode»

Describe Handle

The describe handle is used by the OCI describe call, OCIDescribeAny() . This call obtains information about schema objects in a database (for example, functions, procedures). The call takes a describe handle as one of its parameters, along with information about the object being described. When the call completes, the describe handle is populated with information about the object. The OCI application can then obtain describe information through the attributes of parameter descriptors.

Chapter 6, «Describing Schema Metadata», for more information about using the OCIDescribeAny() function

Complex Object Retrieval Handle

The complex object retrieval (COR) handle is used by some OCI applications that work with objects in an Oracle database server. This handle contains COR descriptors, which provide instructions about retrieving objects referenced by another object.

For information about complex object retrieval and the complex object retrieval handle, refer to «Complex Object Retrieval»

Thread Handle

For information about the thread handle, which is used in multithreaded applications, refer to «The OCIThread Package» .

Subscription Handle

The subscription handle is used by an OCI client application that is interested in registering for subscriptions to receive notifications of database events or events in the AQ namespace. The subscription handle encapsulates all information related to a registration from a client.

For information about publish-subscribe and allocating the subscription handle, refer to «Publish-Subscribe Notification»

Direct Path Handles

The direct path handles are necessary for an OCI application that utilizes the direct path load engine in the Oracle database server. The direct path load interface allows the application to access the direct block formatter of the Oracle server.

Figure 2-6 Direct Path Handles

See Also:

  • For information about direct path loading and allocating the direct path handles, refer to «Direct Path Loading Overview»
  • For information about the handle attributes, refer to «Direct Path Loading Handle Attributes»

Process Handle

The process handle is a specialized handle for OCI applications that utilize shared data structures mode to set global parameters.

Connection Pool Handle

The connection pool handle is used for applications that pool physical connections into virtual connections, by calling specific OCI functions.

Handle Attributes

All OCI handles have attributes associated with them. These attributes represent data stored in that handle. You can read handle attributes using the attribute get call, OCIAttrGet() , and you can change them with the attribute set call, OCIAttrSet() .

For example, the following statements set the username in the session handle by writing to the OCI_ATTR_USERNAME attribute:

Some OCI functions require that particular handle attributes be set before the function is called. For example, when OCISessionBegin() is called to establish a user’s login session, the username and password must be set in the user session handle before the call is made.

Other OCI functions provide useful return data in handle attributes after the function completes. For example, when OCIStmtExecute() is called to execute a SQL query, describe information relating to the select-list items is returned in the statement handle.

See Also:

  • See the description of OCIAttrGet() for an example showing the username and password handle attributes being set
  • For a list of all handle attributes, refer to Appendix A, «Handle and Descriptor Attributes»

User Memory Allocation

The OCIEnvCreate() call, which initializes the environment handle, and the generic handle allocation ( OCIHandleAlloc() ) and descriptor allocation ( OCIDescriptorAlloc() ) calls have an xtramem_sz parameter in their parameter list. This parameter is used to specify memory chunk size which is allocated along with that handle for the user. This memory is not used by OCI and is for use by the application only.

Typically, an application uses this parameter to allocate an application-defined structure, such as for an application bookkeeping or storing context information, that has the same lifetime as the handle.

Using the xtramem_sz parameter means that the application does not need to explicitly allocate and deallocate memory as each handle is allocated and deallocated. The memory is allocated along with the handle, and freeing the handle frees up the user’s data structures as well.

Descriptors

OCI descriptors and locators are opaque data structures that maintain data-specific information. The following table lists them, along with their C datatype, and the OCI type constant that allocates a descriptor of that type in a call to OCIDescriptorAlloc() . The OCIDescriptorFree() function frees descriptors and locators.

Table 2-2 Descriptor Types

LOB datatype locator

FILE datatype locator

read-only parameter descriptor

ANSI DATE descriptor

TIMESTAMP WITH TIME ZONE descriptor

TIMESTAMP WITH LOCAL TIME ZONE descriptor

INTERVAL YEAR TO MONTH descriptor

INTERVAL DAY TO SECOND descriptor

complex object descriptor

advanced queuing enqueue options

advanced queuing dequeue options

advanced queuing message properties

advanced queuing agent

advanced queuing notification

the distinguished names of the database servers in a registration request

Although there is a single C type for OCILobLocator, this locator is allocated with a different OCI type constant for internal and external LOBs. The section below on LOB locators discusses this difference.

The main purpose of each descriptor type is listed here, and each descriptor type is described in the following sections:

  • OCISnapshot — used in statement execution
  • OCILOBLocator — used for LOB (OCI_DTYPE_LOB) or FILE (OCI_DTYPE_FILE) calls
  • OCIParam — used in describe calls
  • OCIRowid — used for binding or defining ROWID values
  • OCIDateTime and OCIInterval — used for datetime and interval datatypes
  • OCIComplexObjectComp — used for complex object retrieval
  • OCIAQEnqOptions, OCIAQDeqOptions, OCIAQMsgProperties, OCIAQAgent — used for Advanced Queuing
  • OCIAQNotify — used for publish-subscribe notification
  • OCIServerDNs — used for LDAP-based publish-subscribe notification

Snapshot Descriptor

The snapshot descriptor is an optional parameter to the execute call, OCIStmtExecute() . It indicates that a query is being executed against a particular database snapshot. A database snapshot represents the state of a database at a particular point in time.

You allocate a snapshot descriptor with a call to OCIDescriptorAlloc() , by passing OCI_DTYPE_SNAP as the type parameter.

For more information about OCIStmtExecute() and database snapshots, see the section «Execution Snapshots»

LOB/FILE Datatype Locator

A LOB (large object) is an Oracle datatype that can hold up to 4 gigabytes of binary (BLOB) or character (CLOB) data. In the database, an opaque data structure called a LOB locator is stored in a LOB column of a database row, or in the place of a LOB attribute of an object. The locator serves as a pointer to the actual LOB value, which is stored in a separate location.

The OCI LOB locator is used to perform OCI operations against a LOB (BLOB or CLOB) or FILE (BFILE). OCILob* functions take the LOB locator as a parameter instead of the LOB value. OCI LOB functions do not take actual LOB data as parameters. These functions take the LOB locators as parameters and operate on the LOB data referenced by these locators.

Hence, the old long interface can operate on the actual LOB value. This descriptor— OCILobLocator—is also used for operations on FILEs.

The LOB locator is allocated with a call to OCIDescriptorAlloc() , by passing OCI_DTYPE_LOB as the type parameter for BLOBs or CLOBs, and OCI_DTYPE_FILE for BFILEs.

The two LOB locator types are not interchangeable. When binding or defining a BLOB or CLOB, the application must take care that the locator is properly allocated using OCI_DTYPE_LOB. Similarly, when binding or defining a BFILE, the application must be sure to allocate the locator using OCI_DTYPE_FILE.

An OCI application can retrieve a LOB locator from the server by issuing a SQL statement containing a LOB column or attribute as an element in the select list. In this case, the application would first allocate the LOB locator and then use it to define an output variable. Similarly, a LOB locator can be used as part of a bind operation to create an association between a LOB and a placeholder in a SQL statement.

The LOB locator datatype ( OCILobLocator) is not a valid datatype when connected to an Oracle7 Server.

For more information about OCI LOB operations, see Chapter 7, «LOB and FILE Operations»

Parameter Descriptor

OCI applications use parameter descriptors to obtain information about select-list columns or schema objects. This information is obtained through a describe operation.

The parameter descriptor is the one descriptor type that is not allocated using OCIDescriptorAlloc() . You can obtain it only as an attribute of a describe, statement, or complex object retrieval handle by specifying the position of the parameter using an OCIParamGet() call.

See Chapter 6, «Describing Schema Metadata», and «Describing Select-List Items» for more information about obtaining and using parameter descriptors

ROWID Descriptor

The ROWID descriptor, OCIRowid, is used by applications that need to retrieve and use Oracle ROWIDs. The size and structure of the ROWID has changed from Oracle release 7 to Oracle release 8, and is opaque to the user. To work with a ROWID using OCI release 8 or later, an application can define a ROWID descriptor for a rowid position in a SQL select-list, and retrieve a ROWID into the descriptor. This same descriptor can later be bound to an input variable in an INSERT statement or WHERE clause.

ROWIDs are also redirected into descriptors using OCIAttrGet() on the statement handle following an execute.

Datetime and Interval Descriptors

These descriptors are used by applications which use the datetime or interval datatypes ( OCIDateTime and OCIInterval). These descriptors can be used for binding and defining, and are passed as parameters to the functions OCIDescAlloc() and OCIDescFree() to allocate and free memory.

For more information about these datatypes refer to Chapter 3, «Datatypes». The functions which operate on these datatypes are listed in Chapter 18, «OCI Datatype Mapping and Manipulation Functions»

The functions which operate on OCIDateTime and OCIInterval datatypes also work on the OCIDate datatype

Complex Object Descriptor

For information about the complex object descriptor and its use, refer to «Complex Object Retrieval» .

Advanced Queuing Descriptors

For information about Advanced Queuing and its related descriptors, refer to «OCI and Advanced Queuing» .

LDAP-based Publish-Subscribe Notification

For information about LDAP-based publish-subscribe notification, see «Publish-Subscribe Registration Functions» .

User Memory Allocation

The OCIDescriptorAlloc() call has an xtramem_sz parameter in its parameter list. This parameter is used to specify an amount of user memory which should be allocated along with a descriptor or locator.

Typically, an application uses this parameter to allocate an application-defined structure that has the same lifetime as the descriptor or locator. This structure maybe used for application bookkeeping or storing context information.

Using the xtramem_sz parameter means that the application does not need to explicitly allocate and deallocate memory as each descriptor or locator is allocated and deallocated. The memory is allocated along with the descriptor or locator, and freeing the descriptor or locator (with OCIDescriptorFree() ) frees up the user’s data structures as well.

The OCIHandleAlloc() call has a similar parameter for allocating user memory which has the same lifetime as the handle.

The OCIEnvCreate() and OCIEnvInit() calls have a similar parameter for allocating user memory which has the same lifetime as the environment handle.

OCI Programming Steps

Each of the steps that you perform in an OCI application is described in greater detail in the following sections. Some of the steps are optional. For example, you do not need to describe or define select-list items if the statement is not a query.

For an example showing the use of OCI calls for processing SQL statements, see the first sample program in Appendix B, «OCI Demonstration Programs»

Description C Type OCI Type Constant

See Also:

  • The special case of dynamically providing data at run time is described in detail in the section «Runtime Data Allocation and Piecewise Operations»
  • Special considerations for operations involving arrays of structures are described in the section «Binding and Defining Arrays of Structures»
  • Refer to the section «Error Handling» for an outline of the steps involved in processing a SQL statement within an OCI program
  • For information on using the OCI to write multithreaded applications, refer to «Thread Safety»
  • For more information about types of SQL statements, refer to the section «SQL Statements»

The following sections describe the steps that are required of an OCI application:

Application-specific processing will also occur in between any and all of the OCI function steps.

OCI programmers should take note that OCI programs no longer require an explicit parse step. This means that 8.0 or later applications must issue an execute command for both DML and DDL statements.

OCI Environment Initialization

This section describes how to initialize the OCI environment, establish a connection to a server, and authorize a user to perform actions against a database.

First, the three main steps in initializing the OCI environment are described in the following sections:

  1. Creating the OCI environment.
  2. Allocating Handles and Descriptors.
  3. Initializing the Application, Connection, and Session.

Creating the OCI Environment

Each OCI function call is executed in the context of an environment that is created with the OCIEnvCreate() call. This call must be invoked before any other OCI call. The only exception is when setting a process-level attribute for the OCI shared mode.

The mode parameter of OCIEnvCreate() specifies whether the application calling the OCI library functions will:

  • Run in a threaded environment ( mode = OCI_THREADED).
  • Use objects ( mode = OCI_OBJECT).
  • Use shared data structures ( mode = OCI_SHARED).
  • Use subscriptions ( mode = OCI_EVENTS).

The mode can be set independently in each environment.

Initializing in object mode is necessary if the application will be binding and defining objects, or if the application will be using the OCI’s object navigation calls. The program may also choose to use none of these features ( mode = OCI_DEFAULT) or some combination of them, separating the options with a vertical bar. For example if mode = (OCI_THREADED | OCI_OBJECT), then the application runs in a threaded environment and use objects.

You can also specify user-defined memory management functions for each OCI environment.

In previous releases, a separate explicit process-level initialization was required. This requirement has been simplified and no explicit process-level initialization is required.

See Also:

  • See the description of OCIEnvCreate() and OCIInitialize() for more information about the initialization calls.
  • For information about using the OCI to write multithreaded applications, refer to «Thread Safety» .
  • For information about OCI programming with objects, refer to Chapter 10, «OCI Object-Relational Programming» and the chapters that follow it.
  • For information about using the publish-subscribe feature, see «Publish-Subscribe Notification» .

Shared Data Mode

When a SQL statement is processed, certain underlying data is associated with the statement. This data includes information about statement text and bind data, as well as define and describe information for queries. For applications where the same set of SQL statements is executed on multiple instances of the application on the same host, the data can be shared.

When an OCI application is initialized in shared mode, common statement data is shared between multiple statement handles, thus providing memory savings for the application. This savings may be particularly valuable for applications which create multiple statement handles which execute the same SQL statement on different users’ sessions but in the same schema, either on the same or multiple connections.

Without the shared mode feature, each execution of the query using an OCI statement handle requires its own memory for storing the metadata. The total amount of memory required is roughly equal to the number of statements being executed in all the processes combined multiplied by the memory required for each statement handle.

A large part of the common memory in a statement handle is shared among all the processes executing the same statement with the shared mode feature. The total amount of memory in all the processes combined is much less than in the previous case for the same number of processes. The memory requirement for each statement handle is much smaller than in the case where there is no sharing, as the number of such statements increases to a large number.

Shared data structure mode can be useful in the following scenarios:

  • When several instances of the same application are running on the same machine to service multiple clients. Each of these instances may be executing identical SQL statements, differentiated by different bind values.
  • When an application process forks service threads to execute the same statement for different users either on the same connection or on multiple connections. The same saving as above can be realized in this scenario too.
  • Where the types of applications are SQL drivers and other middle-tiered applications.

Small applications, which execute single queries non-concurrently do not benefit from this feature.

There are several ways to use the shared OCI functionality. Existing applications can quickly examine the benefits of this feature without changing any code. These applications can be initialized in OCI shared mode by setting environment variables. New applications should use OCI API calls to initialize shared mode functionality.

Using OCI Functions

To initialize OCI shared mode functionality, process handle parameters must be set and OCIEnvCreate() must be called with the mode flag set to OCI_SHARED. For example:

The first application that initializes OCI in shared mode starts up the shared subsystem using the parameters set by that OCI application. When subsequent applications initialize using the shared mode, they use the previously started shared subsystem.

For information on the parameters that can be set and read for the OCI shared mode system, see «Process Handle Attributes» .

If an OCI application has been initialized in shared mode, all statements that are prepared and executed use the shared subsystem by default. If you do not want to use the shared subsystem to execute a specific SQL statement, then you can use the OCI_NO_SHARING flag in OCIStmtPrepare() . For example:

The OCI_NO_SHARING flag has no effect if the process has not been initialized in the shared mode.

To detach a process from the shared memory subsystem, use the OCITerminate() call.

Using Environment Variables

The environment variables OCI_SHARED_MODE and OCI_NUM_SHARED_PROCS can be used to set OCI shared mode functionality. However, this is not the recommended method. This procedure lets you to quickly examine the benefits of using shared mode functionality in existing applications.

OCI_SHARED_MODE

To initialize an OCI application to run in shared mode, set the environment variable OCI_SHARED_MODE before executing a OCI program. To set the variable in the C-shell under Solaris TM Operating Environment, for example, issue the command:

where number is the size of the shared memory address space. For example:

If the shared subsystem is not already running, setting this variable launches the subsystem by creating a shared memory address space with the size specified. The size of the shared memory required is determined by the nature of the application and depends on the size and type of the SQL statement and the underlying table(s) that it accesses.

To set the maximum number of processes that can connect to the shared subsystem, set the environment variable ORA_OCI_NUM_SHARED_PROCS. To set this variable, issue the command:

where number is the maximum number of processes. For example:

ORA_OCI_NUM_SHARED_PROCS is an initialization parameter for starting the shared subsystem. It has no effect if the shared subsystem is already running.

Allocating Handles and Descriptors

Oracle provides OCI functions to allocate and deallocate handles and descriptors. You must allocate handles using OCIHandleAlloc() before passing them into an OCI call, unless the OCI call, such as OCIBindByPos() , allocates the handles for you.

You can allocate the following types of handles with OCIHandleAlloc() :

  • error handle.
  • service context handle.
  • statement handle.
  • describe handle.
  • server handle.
  • user session handle.
  • transaction handle.
  • connection pool handle
  • complex object retrieval handle.
  • subscription handle.
  • direct path context handle.
  • direct path column array handle.
  • direct path stream handle

Depending on the functionality of your application, it needs to allocate some or all of these handles.

Application Initialization, Connection, and Session Creation

An application must call OCIEnvCreate() to initialize the OCI environment handle.

Following this step, the application has two options for establishing a server connection and beginning a user session: Single User, Single Connection; or Multiple Sessions or Connections.

OCIEnvCreate() should be used instead of the OCIInitialize() and OCIEnvInit() calls. OCIInitialize() and OCIEnvInit() calls are supported for backward compatibility.

Option 1: Single User, Single Connection

This option is the simplified logon method.

If an application maintains only a single user session for each database connection at any time, the application can take advantage of the OCI’s simplified logon procedure.

When an application calls OCILogon() , the OCI library initializes the service context handle that is passed to it and creates a connection to the specified server for the user whose username and password are passed to the function.

The following is an example of what a call to OCILogon() might look like:

The parameters to this call include the service context handle (which are initialized), the username, the user’s password, and the name of the database that are used to establish the connection. The server and user session handles are also implicitly allocated by this function.

If an application uses this logon method, the service context, server, and user session handles will all be read-only, which means that the application cannot switch session or transaction by changing the appropriate attributes of the service context handle, using OCIAttrSet() .

An application that initializes its session and authorization using OCILogon() should terminate them using OCILogoff() .

Option 2: Multiple Sessions or Connections

This option uses explicit attach and begin session calls.

If an application needs to maintain multiple user sessions on a database connection, the application requires a different set of calls to set up the sessions and connections. This includes specific calls to attach to the server and begin sessions:

  • OCIServerAttach() creates an access path to the data server for OCI operations.
  • OCISessionBegin() establishes a session for a user against a particular server. This call is required for the user to be able to execute any operation on the server.

See «Nonblocking Mode» for information about specifying a blocking or nonblocking connection in the OCIServerAttach() call.

These calls set up an operational environment that lets you to execute SQL and PL/SQL statements against a database. The database must be up and running before the calls are made, or else they will fail.

These calls are described in more detail in «Connect, Authorize, and Initialize Functions» . Refer to Chapter 9, «OCI Programming Advanced Topics», for more information about maintaining multiple sessions, transactions, and connections.

The following example demonstrates the use of creating and initializing an OCI environment. In the example, a server context is created and set in the service handle. Then a user session handle is created and initialized using a database username and password. For the sake of simplicity, error checking is not included.

The demonstration program cdemo81.c in the demo directory illustrates this process, with error-checking.

Processing SQL Statements

For information about processing SQL statements, refer to Chapter 4, «Using SQL Statements in OCI».

Commit or Rollback

An application commits changes to the database by calling OCITransCommit() . This call takes a service context as one of its parameters. The transaction currently associated with the service context is the one whose changes are committed. This may be a transaction explicitly created by the application or the implicit transaction created when the application modifies the database.

Using the OCI_COMMIT_ON_SUCCESS mode of the OCIExecute() call, the application can selectively commit transactions at the end of each statement execution, saving an extra round-trip.

If you want to roll back a transaction, use the OCITransRollback() call.

If an application disconnects from Oracle in some way other than a normal logoff (for example, losing a network connection), and OCITransCommit() has not been called, all active transactions are rolled back automatically.

For more information about implicit transactions and transaction processing, see the section «Service Context and Associated Handles» , and the section «OCI Support for Transactions»

Terminating the Application

An OCI application should perform the following three steps before it terminates:

  1. Delete the user session by calling OCISessionEnd() for each session.
  2. Delete access to the data source(s) by calling OCIServerDetach() for each source.
  3. Explicitly deallocate all handles by calling OCIHandleFree() for each handle.
  4. Delete the environment handle, which deallocates all other handles associated with it.

When a parent OCI handle is freed, any child handles associated with it are freed automatically

The calls to OCIServerDetach() and OCISessionEnd() are not mandatory, but are recommended. If the application terminates, and OCITransCommit() (transaction commit) has not been called, any pending transactions are automatically rolled back

For an example showing handles being freed at the end of an application, refer to the first sample program in Appendix B, «OCI Demonstration Programs»

If the application has used the simplified logon method of OCILogon() , then a call to OCILogoff() terminates the session, disconnects from the server, and frees the service context and associated handles. The application is still responsible for freeing other handles it has allocated.

Error Handling

OCI function calls have a set of return codes, listed in Table 2-3, «OCI Return Codes», which indicate the success or failure of the call, such as OCI_SUCCESS or OCI_ERROR, or provide other information that may be required by the application, such as OCI_NEED_DATA or OCI_STILL_EXECUTING. Most OCI calls return one of these codes.

Table 2-3 OCI Return Codes

The function completed successfully.

The function completed successfully; a call to OCIErrorGet() returns additional diagnostic information. This may include warnings.

The function completed, and there is no further data.

The function failed; a call to OCIErrorGet() returns additional information.

An invalid handle was passed as a parameter or a user callback is passed an invalid handle or invalid context. No further diagnostics are available.

The application must provide run-time data.

The service context was established in nonblocking mode, and the current operation could not be completed immediately. The operation must be called again to complete. OCIErrorGet() returns ORA-03123 as the error code.

This code is returned only from a callback function. It indicates that the callback function wants the OCI library to resume its normal processing.

If the return code indicates that an error has occurred, the application can retrieve Oracle-specific error codes and messages by calling OCIErrorGet() . One of the parameters to OCIErrorGet() is the error handle passed to the call that caused the error.

Multiple diagnostic records can be retrieved by calling OCIErrorGet() repeatedly until there are no more records (OCI_NO_DATA is returned). OCIErrorGet() returns at most a single diagnostic record at any time.

The following example code returns error information given an error handle and the return code from an OCI function call. If the return code is OCI_ERROR, the function prints out diagnostic information. OCI_SUCCESS results in no printout, and other return codes print the return code information.

Return and Error Codes for Truncation and Null Data

In Table 2-4, Table 2-5, and Table 2-6, the OCI return code, Oracle error number, indicator variable, and column return code are specified when the data fetched is null or truncated.

See «Indicator Variables» for a discussion of indicator variables.

Источник

Adblock
detector

OCI Return Code Description

У меня проблема с жабой для Oracle 9.1, работающей на Windows 7 32-бит, описывается следующим образом:

на моем ПК установлен Oracle OraClient10g 10.0.2, и мне нужно использовать Toad 9.1. Когда я пытаюсь войти в сервер, я указываю базу данных через TNS, я ввожу имя пользователя и пароль, но я получаю сообщение со следующей ошибкой:

не удается инициализировать OCI. Ошибка -1

Googling around у меня есть несколько вариантов, которые включают в себя: проверьте, что ORACLE_HOME переменная среды установлена правильно, запустите TOAD как администратор, проверьте правильность имени пользователя и пароля, установите Oracle и TOAD для 32-битной системы… Я проверил все эти параметры, но я все еще получаю ошибку.

есть, однако, деталь, которую я должен упомянуть: в моем меню «Пуск» есть два дома Oracle (Home1 и Home2). Home 2 указывает на пустую папку, потому что я переустановил Oracle во время моих попыток решить проблему, и короткий путь все еще находится в моем начале меню. Я не думаю, что это важно, потому что ORACLE_HOME указывает на правильный дом.

Мне действительно нужна помощь с этим. Мне нужно решить эту ошибку и войти в систему с помощью TOAD.

10 ответов


Я открыл жабу с правами администратора (Right click -> Run as Administrator). Проблема решена.

Спасибо большое!


для меня эта проблема была вызвана меня задание ORACLE_HOME переменная среды windows (постоянно). Я установил это, пытаясь получить "emctl" на работу.

после удаления жаба работала нормально.


удаление ORACLE_HOME из переменных среды (системы) работало для меня.
Жаба теперь работает нормально.

2

автор: Jose Pedro Almeida


проблема решена: я изменил переменные среды, в том числе в реестре Windows, и жаба показала Oracle home красным цветом в меню TNS. Я поставил переменные среды так, как они могли бы соединиться с Toad… Странно, но сейчас это работает.


в моем случае я получал ту же ошибку с клиентом Oracle 10g, Toad 10 Commercial, установленным на моем ПК с Windows 7. Я пытался получить доступ к серверу Oracle 10G с моего ПК.
Я получал эту ошибку, пытаясь получить доступ от Toad.

наконец, решение, которое я нашел, было :
Я открыл toad с правами администратора (щелкните правой кнопкой мыши -> Запуск от имени администратора). Проблема решена.


Не уверен, что другие вещи установлена на вашем ноутбуке / рабочий стол.
Но у меня была жаба 11.6, а затем я установил другой продукт oracle realted, который создал другие дома. Ниже предложения сделали не работать на меня :

  • Regedit — > программное обеспечение — > Wow6432Node — > Oracle — > KEY_ORA_WF_NK имеет правильный ORACLE_HOME
  • переменная среды ORACLE_HOME в локальной системе также имеет то же самое.

вместо этого я попытался ниже, и это сработало для меня и вот еще одно предложение:

  • когда вы открываете жабу, вам обычно предлагается, какую БД подключить, и есть возможность выбрать («…») рядом со списком установленных домов, как только вы нажмете там, он укажет ошибку (при нажатии кнопки), поэтому я попробовал это и что-то жаловался на то, что путь не установлен, как только я исправил путь, и он работал. После этого жаба открывается нормально (т. е. не нужно использовать опцию Run As Admin).

BTW: Прежде чем пытаться исправить выше , я попытался запустить как администратор, и это сработало.

надеюсь, это поможет, если не извините меня.

1

автор: BB-on-StackOverflow


великолепно!!

он работает после того, как эти две вещи синхронизированы:

  1. Regedit -> Softerware -> Wow6432Node -> Oracle -> KEY_ORA_WF_NK has correct ORACLE_HOME
  2. переменные среды ORACLE_HOME в локальной системе также есть то же самое.

Я получил эту ошибку «OCI_INVALID_HANDLE» во время подключения к удаленной базе данных после удаления одной из моих избыточных установок клиента Oracle 12c DB. ОС моей машины-Windows 10 Enterprise. Проблема устранена путем добавления ключа ORACLE_HOME в путь к системной среде.

поскольку у меня нет ключа ORACLE_HOME в моем пути к системной среде, я создаю его, выполнив следующие шаги:

  1. щелкните правой кнопкой мыши на «этот ПК»
  2. клик «Свойства» — > » расширенная система
    настройки»
  3. нажимаем «переменные среды…»в вкладке «Дополнительно»
  4. Нажать «Новая…»в разделе» системные переменные»
  5. поместите «ORACLE_HOME» в
    Поле «имя переменной» и укажите путь установки oracle db
    клиент (ex: C:oracleproduct12.1.0client_1) в разделе » значение переменной»
    поле
  6. Нажмите «Ok».

enter image description here


возможно, у вас будут установлены Oracle и Oracle Express, поэтому любые переменные среды конфигурации могут быть изменены, если это так, вход прямой, а не TNSNAME и настройки будут localhost 1521 вариант serviceName: xe, оставляя подключение с использованием всегда клиента oracle, например Instant Client — 11.2


Windows 7 блокирует диск C вот почему работает как администратор.


Toad World® Forums

Loading

Toad World by Quest

Понравилась статья? Поделить с друзьями:
  • Ошибка or pmia 14 что это
  • Ошибка ora 29273 что это
  • Ошибка out of memory shadow warrior
  • Ошибка or imira 34 что означает
  • Ошибка out of memory exiting the application