PDA

View Full Version : QOCIDriver: unable to create environment



thaihoangluu
8th May 2012, 08:38
Hi verybody.
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:

#include <QApplication>
#include <QtSql>
#include <QtPlugin>


#include <iostream>
using namespace std;

/* Change these to match your database */
#define HOST "127.0.0.1"
#define DB "xe"
#define PORT 1521
#define USER "testbed"
#define PASSWD "secre3t"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);


// QSqlDatabase db = QSqlDatabase::addDatabase(ociDriver->create("QOCI"));

QSqlDatabase qDB = QSqlDatabase::addDatabase("QOCI");

qDB.setHostName(HOST);
qDB.setDatabaseName(DB);
qDB.setPort(PORT);
qDB.setUserName(USER);
qDB.setPassword(PASSWD);

/* Probably overkill ;) */
qDB.setConnectOptions("Prefetch_Memory=5242880;Prefetch_Rows=250");

if (qDB.open() == FALSE) {
cout<< "Error: opening DB failed because " << qDB.lastError().text().toStdString();
return -1;
}


return 0;
}

Errors:
QOCIDriver: unable to create environment
QOCIDriver:: parseArgs: Invalid parameter: 'Prefetch_Memory'
QOCIDriver:: parseArgs: Invalid parameter: 'Prefetch_Rows'
Unable to free Error handle: -1
Unable to free Environment handle: -1

I set variables enviroment here:
Name: Path
Value: C:\oraclexe\app\oracle\product\11.2.0\server\bin;; C:\app\nguyenluuvu\product\11.2.0\client;C:\app\ng uyenluuvu\product\11.2.0\client_1\bin;E:\app\nguye nluuvu\product\11.2.0\client_1;C:\app\MAY02\produc t\11.2.0\dbhome_1\bin;%SystemRoot%\system32;%Syste mRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\Sys tem32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Prog ram Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseHg\;C:\MinGW\bin\; C:\msys\1.0\bin\;C:\luuvu\MinGW\bin;C:\Program Files\CMake 2.8\bin;C:\luuvu\qt\bin;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\OPENCV;C:\App\nguyenluuvu\product\11.2.0\cli ent_1\oci\include;C:\App\nguyenluuvu\product\11.2. 0\client_1\oci\lib\msvc;C:\Windows\System32;C:\luu vu\qt\plugins\sqldrivers\qopenocci.dll;C:\oraclexe \app\oracle\product\11.2.0\instantclient_11_2;C:\o raclexe\app\oracle\product\11.2.0\server\bin;C:\Wi ndows\System32;C:\oraclexe\app\oracle\product\11.2 .0\server\oci\lib\MSVC;C:\oraclexe\app\oracle\prod uct\11.2.0\server\oci\include



Can you help me?
Thanks so much!

ChrisW67
8th May 2012, 09:04
The errors generated by line 32 are self-explanatory, your options do not appear in the list here: QSqlDatabase::setConnectOptions()

thaihoangluu
8th May 2012, 09:14
The errors generated by line 32 are self-explanatory, your options do not appear in the list here: QSqlDatabase::setConnectOptions()

Oh, i'm sorry :(

this code:
#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.

ChrisW67
8th May 2012, 23:09
You don't say whether the database connection opens or not. The first line is a Qt warning, not an error. The warning results when OCIEnvCreate() (not a Qt function) fails. A quick search suggests this is either an incorrect ORACLE_HOME or permissions related: can your user read the directories under ORACLE_HOME?

thaihoangluu
9th May 2012, 07:01
You don't say whether the database connection opens or not. The first line is a Qt warning, not an error. The warning results when OCIEnvCreate() (not a Qt function) fails. A quick search suggests this is either an incorrect ORACLE_HOME or permissions related: can your user read the directories under ORACLE_HOME?



#include <QtCore>
#include <QtSql>
#include <QSqlDatabase>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
QSqlDatabase qdb = QSqlDatabase::addDatabase("QOCI");//If I replace "QOCI" = "QODBC" -> It's okay.

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;
}

How to fix error QOCIDriver: unable to create environment .Hizzzz

thaihoangluu
9th May 2012, 09:51
Dear ChrisW67
Can you help me? Please !

ChrisW67
9th May 2012, 11:53
I already have...

The warning results when OCIEnvCreate() (not a Qt function) fails. A quick search suggests this is either an incorrect ORACLE_HOME or permissions related: can your user read the directories under ORACLE_HOME?

Have you checked these things?

thaihoangluu
10th May 2012, 02:20
I already have...


Have you checked these things?
How do you define Oracle_Home -> i don't know this.
Sorry if my question stupid :p

Do you guide me with image?
thanks so much.

ChrisW67
10th May 2012, 04:51
ORACLE_HOME is an environment variable, or on Windows a registry entry, that almost all Oracle utilities use to find, among other things, the Oracle client and connection information files. ORACLE_HOME has nothing to do with Qt specifically and is set outside your program. ORACLE_HOME is generally set by the Oracle client installer. I suggest you need to consult your Oracle DBA or Oracle documentation.

http://www.orafaq.com/wiki/ORACLE_HOME

thaihoangluu
10th May 2012, 05:24
Thank you.
I set varible environment :
Name: ORACLE_HOME
Value: C:\oraclexe\app\oracle\product\11.2.0\server

But it's error :(

ChrisW67
10th May 2012, 05:39
Take the "/server" off the end. The example in the FAQ I linked stops at the version numbered folder. You should be able to find a folder "bin" (usually contains sqlplus) in the folder pointed to by ORACLE_HOME.

thaihoangluu
10th May 2012, 07:43
Take the "/server" off the end. The example in the FAQ I linked stops at the version numbered folder. You should be able to find a folder "bin" (usually contains sqlplus) in the folder pointed to by ORACLE_HOME.

I tried all suggest , but it's nothing to effective :(



It's my HOME PATH ORACLE FOLDER.
7712
Can you tell me Set variable environtment please?

ChrisW67
10th May 2012, 08:32
Where is sqlplus.exe? Ignoring your program for the time being, can sqlplus connect to your database (http://docs.oracle.com/cd/E17781_01/server.112/e18804/connecting.htm#CHDCHJFD)?

I do not propose to download and install an entire RDBMS just to answer your question.

thaihoangluu
10th May 2012, 09:09
Where is sqlplus.exe? Ignoring your program for the time being, can sqlplus connect to your database (http://docs.oracle.com/cd/E17781_01/server.112/e18804/connecting.htm#CHDCHJFD)?

I do not propose to download and install an entire RDBMS just to answer your question.

I don't know @@
I have followed all instructions but when running any program error!!!!

ChrisW67
10th May 2012, 09:49
I know your program generates error messages, you do not need to keep saying that. The situation will not change until you start applying some effort to identifying the problem.

thaihoangluu
10th May 2012, 10:09
I know your program generates error messages, you do not need to keep saying that. The situation will not change until you start applying some effort to identifying the problem.

I connect MS SQL Server successfully but connect Oracle is very Complex @@

ChrisW67
11th May 2012, 00:15
No, the Oracle client software needs to be installed correctly to be used. This is no different to the Microsoft SQL Server client, except that Microsoft install it with Windows.

How have you installed the Oracle client software? Do any of the Oracle utilities function for connecting to the database?

thaihoangluu
11th May 2012, 02:14
No, the Oracle client software needs to be installed correctly to be used. This is no different to the Microsoft SQL Server client, except that Microsoft install it with Windows.

How have you installed the Oracle client software? Do any of the Oracle utilities function for connecting to the database?


How to install Oracle correctly?

Step 1: I install Oracle Database Express Edition 11g Release 2. http://www.oracle.com/technetwork/products/express-edition/downloads/index.html?ssSourceSiteId=ocomen

Step 2: I install Instant Client Downloads.http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html?ssSourceSiteId=ocomen

Am I correct?

If I false please guide me Install Oracle. :)

Thanks and sorry if My English is bad :(

ChrisW67
11th May 2012, 03:20
Where is sqlplus.exe? Ignoring your program for the time being, can sqlplus connect to your database?

Do any of the Oracle utilities function for connecting to the database?

This is the last time I will ask:
Do any of the Oracle supplied utilities work to connect to your database?