I seem to be getting an unhandled exception though... Throws an exception when trying to connect... My Username : example Password : example Conn : XE are all correct because i can access the DB
I seem to be getting an unhandled exception though... Throws an exception when trying to connect... My Username : example Password : example Conn : XE are all correct because i can access the DB
That's where all this try/catch code comes in handy:
Can you post a small sample of your code, at least the code around where you attempt to do the env->CreateConnection call?Code:// Make sure we get a connection to the database in question, otherwise quit. try { cout << "Enter password for user YOUR_USER_HERE: "; cin >> strPass; conn = env->createConnection(strUser,strPass,strConn); } catch (SQLException &sqlExcp) { cerr << sqlExcp.getErrorCode() << ": " << sqlExcp.getMessage() << "Press a key to continue..." << endl; cin.ignore(); // Ignore previous ws cin.get(); Environment::terminateEnvironment(env); return EXIT_FAILURE; }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
The red part doesn't print "Press a key to continue" instead i get 24960: printed and a Microsoft DEBUG error window with don't send/send error options ... I think it throws an exception on the red partCode:Environment * env = Environment::createEnvironment(); Connection * conn = NULL; const string strUser = "example"; // User we connect as const string strConn = "XE"; // Database connection string strPass; // Password for above // Make sure we get a connection to the database in question, otherwise quit. try { cout << "Enter password for user YOUR_USER_HERE: "; cin >> strPass; conn = env->createConnection(strUser,strPass,strConn); } catch (SQLException &sqlExcp) { cerr << sqlExcp.getErrorCode() << ": " << sqlExcp.getMessage() << "Press a key to continue..." << endl; cin.ignore(); // Ignore previous ws cin.get(); Environment::terminateEnvironment(env); return EXIT_FAILURE; }
What's your TNS_NAMES file look like (if you don't mind ...you can omit stuff like IP addresses)?
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Code:XE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = officepc)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE) ) ) EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) ORACLR_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE)) ) (CONNECT_DATA = (SID = CLRExtProc) (PRESENTATION = RO) ) )
i didn;t specify any ip address anywhere AFAIC
I think this might be a DLL issue... since the code seems to compile/link fine. In the instructions for downloading/installing the library code you were instructed to unzip the Oracle libraries somewhere (there should have been some DLLs for you to download [or maybe they came with everything else] as well). Can you verify all the libraries .LIB and .DLL that you've downloaded. Also there were those instructions to put the location (the folder path) of the .DLL files into your path environment variable. Did you do that?
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Project properties and the dependencies takes care of the .lib issues and linking. Setting up the PATH such that the folder where the .dll files are is included takes care of those (according to the instructions) They are probably in the same location so your first PATH setting should also be pointing to that same folder as in your project's "Additional Library Directories". You should have the following LIB/DLLs present wherever they may be:
I've also got a couple other files in that directory for whatever reason:oci.dll
ocijdbc.dll
ociw32.dll
orannzsbb10.dll
oraocci10.dll
oraocci10.lib
oraocci10d.dll
oraocci10d.lib
oraociei10.dll
classes12.jar
occivc8_102030_Readme.txt
ojdbc14.jar
oraocci10.dll.manifest
oraocci10d.dll.manifestWhen you click on Post Reply, there is an area titled "Additional Options" with a "Manage Attachments" button. Click on that button and another pop-up window should appear where you can browse files on your computer and then click on the "Upload" button for each file you wish to attach. When you're done with all the files you want to attach you can close the pop-up window with the "Close this Window" button. When you finally post, those files will be attached to your post.Originally Posted by csonx_p
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
this statement ...
its what's throwing "Access violation reading location 0xcccccccc", i doubt if it has anything to do with the libraries ...Code:sqlExcp.getMessage()
This code
probably threw an exception and was catched ...Code:conn = env->createConnection(strUser,strPass,strConn);
but then somehow sqlExcp.getMessage() is throwing another exception ???Code:try { cout << "Enter password for user YOUR_USER_HERE: "; cin >> strPass; conn = env->createConnection(strUser,strPass,strConn); } // HERE ... catch (SQLException &sqlExcp) { cerr << sqlExcp.getMessage() << "Press a key to continue..." << endl; cin.ignore(); // Ignore previous ws cin.get(); Environment::terminateEnvironment(env); return EXIT_FAILURE; }
Well, if you've got an exe then the compiling/linking went fine which means the static libs were found and that part of the equation is fine. The only thing I can think of is that you should:
- Make sure all the DLLs I've mentioned previously are all present.
- Make sure you've got the path environment variable set properly.
- Possibly set the TNS_ADMIN environment variable as well.
It might also be that the createEnvironment call fails (this would mean you're dereferencing a bad pointer [env->] which might be the problem), you could check the value of that call and make sure it isn't null.
Code:Environment * env = 0; env = Environment::createEnvironment(); ... if(!env) { // Bad stuff has happened } else { // Everything's cool }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Please check the attached files for project properties and libraries ... the file listing image is the location "C:\oraclexe\app\oracle\product\10.2.0\server\OCI\ lib\MSVC\vc8" which is added as additional link/libraries.. Note that i have oracle server installed not client ...
Last edited by csonx_p; 04-14-2009 at 11:21 AM.
Go here: Instant Client Downloads
- Choose the appropriate link according to your installation.
- In the next page you need to click on the "Accept License Agreement" button.
- Download the appropriate "Instant Client Package - Basic" that closely matches your Oracle version (you'll probably either want 10.2.0.4 or 10.2.0.3)
- Unzip the files to that folder location where you've got all the other DLL/LIB files (you can just overwrite any of your files that are there already).
- The ZIP should include the file you're missing (oraociei10.dll).
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens