You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, February 1st 2006, 5:34pm

QOCIDriver: unable to create environment

I can't seem to get past step one. I using v3.3.4, enterprise edition.

I want to connect to an oracle database. I've got the client.

When I execute the following:

QSqlDatabase *db = QSqlDatabase::addDatabase("OCI8", "RICK");

I get the following:
QOCIDriver: unable to create environment
QOCIDriver: unable to alloc error handle
QOCIDriver: unable to alloc service context

I then go on to set the database, user, password and open the db.

At that point I get:
Failed to open database: QOCI: unable to login

I'm not sure if the first messages are what's the problem or if I have some problems with name or password.

Thanks,
Rick

2

Thursday, February 2nd 2006, 4:05pm

RE: QOCIDriver: unable to create environment

These messages are a result of not having the Oracle Client setup properly. I got that squared away and no more problem.

ksekera

Beginner

  • "ksekera" is female

Posts: 2

Occupation: Software Engineer

  • Send private message

3

Monday, January 22nd 2007, 7:37pm

RE: QOCIDriver: unable to create environment

I am currently having the same issues with my program.
Does anyone have any vague ideas on what I could possibly be doing wrong? I'm not that great of a database programmer... actually, this is my first stab at it.

I'm currently using Qt 4.2.0 and Oracle Client 10g.

The program compiles and runs until the QSqlDatabase::addDatabase( "QOCI" ) call. At this point it outputs the following two lines to the debug screen:

QOCIDriver: unable to create environment:
QOCIDriver: unable to alloc error handle:


I thought I had set up the Client correctly, but as this is my first time I'm not exactly sure. I am able to access my database through SQL*Plus and the oracle SQL Developer application.

Thanks in advance for any assistance.

4

Monday, March 26th 2007, 2:29pm

RE: QOCIDriver: unable to create environment

All,

I have the exact same problem as above. Whenever I try to use my QOCI driver I get

QOCIDriver: unable to create environment:
QOCIDriver: unable to alloc error handle:

Someone replied that 'you have your OCI client installed wrong', is there some sort of elaboration that can be given. On windows you kinda just hit 'Next...Next...Next' on the OCI install, so not sure how I would do it differently.

prazak

Beginner

Posts: 27

Location: seattle, USA

  • Send private message

5

Wednesday, July 11th 2007, 9:30pm

Yo, Exact same problem here. Any elaboration on what needed to be done with the oracle client?

ksekera

Beginner

  • "ksekera" is female

Posts: 2

Occupation: Software Engineer

  • Send private message

6

Wednesday, July 11th 2007, 9:58pm

RE: QOCIDriver: unable to create environment

I solved this a while ago, so this solution may or may not help, but I think these are the steps I took...

I have Oracle Client 10.2.0 installed on my PC and this is where I am getting the oci.lib to link against.

Oracle Client also has a "tnsping" executable that helps find all the databases that you have defined in your "tnsnames.ora" file in your Oracle Client directory. If you run a command at the prompt like, "tnsping myDatabase" and it does not return with the last line saying "OK", then you cannot connect to your database.

My understanding is that Oracle does all its database lookups by name, so you have to define what that name should evaluate to in the tnsname.ora file. You can either create this in a text editor of your choice, or if you have the application that comes with Oracle Client, "Net Manager" or Net Configuration Assistant (or some other similar name) you can define your name lookup through their assistant tools which will generate the tnsnames.ora file for you.

My file looks similar to this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
# tnsnames.ora Network Configuration File: C:oracleproduct10.2.0client_1tnsnames.ora
# Generated by Oracle configuration tools.

MyDatabase =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = MyDatabasePcHostName)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = MyDatabase)
)
)


I also had to define the following Environment Variables and set them equal to my Oracle installation directory, but as I did them all at once, I'm not sure if they are all required:

ORACLE_HOME
SQLPATH
TNS_ADMIN

Hope this helps!

prazak

Beginner

Posts: 27

Location: seattle, USA

  • Send private message

7

Wednesday, July 11th 2007, 10:10pm

hello, I appreciate your quick reply.

You mention naming the database you are connecting to via the tsnames.ora file. I am familiar with this file and have an entry in it for my database.

Do you refer to this name when you connect?

To use your values is this how you would connect?:

Source code

1
2
3
4
5
6
7
 QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
db.setDatabaseName("MyDatabase");
db.setHostName("MyDatabasePcHostName");
db.setUserName("userid");
db.setPassword("*******");
db.setPort(1521);
bool ok = db.open();

prazak

Beginner

Posts: 27

Location: seattle, USA

  • Send private message

8

Thursday, July 12th 2007, 8:02pm

I set the ORACLE_HOME environment variable, changed the oracle install directory to have "execute" permissions. That made it work.

9

Wednesday, May 9th 2012, 9:48am

Hi everybody

I'm trying to connect Oracle Database using QOCI Driver.
I used QT Eclipse Plugin + MINGW + Eclipse C++ + Window 7.

I complied OCI.DLL success.
But when I run my code here:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <QtCore>
#include <QtSql>
#include <QSqlDatabase>

#include <iostream> 

using namespace std;

int main(int argc, char *argv[])
{
QSqlDatabase qdb = QSqlDatabase::addDatabase("QOCI");

qdb.setHostName("localhost");
qdb.setDatabaseName("test");
qdb.setUserName("postgres");
qdb.setPassword("1234");
qdb.setPort(1521);

if(qdb.open())
{
cout << "Database connection successful!" << endl;
}
else
{
cout << "Database connection not successful!" << endl;
}

qdb.close();
return 0;
} 


Errors:
QOCIDriver: unable to create environment
Unable to free Error handle: -1
Unable to free Environment handle: -1

I encountered this problem.
Help me, please.

10

Wednesday, May 9th 2012, 10:24pm

and have you read and tried all suggestions in the thread?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

11

Thursday, May 10th 2012, 2:35am

and have you read and tried all suggestions in the thread?
híc, I tried all
suggestions in the thread. And It's not work :(