8

I'm receiving the following error when trying to do a PDO OCI SQL query on one of my web servers:

SQLSTATE[HY000]: OCISessionBegin: ORA-21561: OID generation failed

I've confirmed that the Oracle server is accessible from the machine and network configuration looks fine. Google returns very few, and not very helpful results.

Has anyone else run into this, or have any suggestions on how to resolve?

Camden S.
  • 2,185
  • 1
  • 22
  • 27
  • 1
    could you show PDO constructor params and tnsnames.ora (check if hostnames are same in both places) – ziollek Oct 29 '13 at 16:41
  • I actually just thought to bypass PDO altogether and just use OCI, and received a more helpful error message which led to a quick solution -- sorry for the trouble. I'll post my findings as answer in case it helps anyone else. – Camden S. Oct 29 '13 at 16:46

3 Answers3

13

I was facing the same issue. I was trying to connect to database on my localhost. This is how I solved it.

  • Get the hostname

    > hostname 
    localhost.idc.company.com
    
  • Add this name to /etc/hosts file

    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 localhost.idc.company.com
    
apaderno
  • 28,547
  • 16
  • 75
  • 90
Husmus
  • 841
  • 1
  • 10
  • 23
  • Adding the hostname to the /etc/hosts file for localhost also worked for me, even though I was connecting to a remote Oracle server. So even if you've got a remote server, try this fix. – Tim Holt May 25 '16 at 17:24
1

I decided to forego the use of PDO and just tried to use an OCI_Connect() function to connect to the database and received the following message:

"ORA-24408: could not generate unique server group name"

... I did battle with that a while back and the answer is here: ORA-24408: could not generate unique server group name

I'm just posting it here in case anyone encounters a similar error. Hope that helps someone.

Community
  • 1
  • 1
Camden S.
  • 2,185
  • 1
  • 22
  • 27
1

This can be fixed with a simple edit of your hosts file:

Find out name of your localhost system by just typing 'hostname' in terminal/Command Prompt. Let's assume your machine is called 'the_machine' then edit your /etc/hosts file to : 127.0.0.1 localhost the_machine

  1. $hostname :

    the_machine

  2. $vi /etc/hosts :

127.0.0.1 localhost the_machine

  1. $python Connect_to_Oracle_DB.py

Cheers!