Wednesday, December 8, 2010

Hey friends here i am writing a simple code of oracle connectivity with VC++.

#include < iostream.h>
#include < windows.h>
#include < stdlib.h>
#include < stdio.h>
#include < string>
#include "ocl.h" // include OCL header

int main(/*int argc, char **argv*/)
{
COraSession session;
COraDataset dataset(session);

//OraCommand cmd(session);
int recordCount = 0;
char* connectString = "content/content@mivas"; // replace ora with your TNS alias
//char* connectString = "id/password@ora"; // replace ora with your TNS alias

try {
session.setConnectString(connectString); // set login information
cout << "Connecting as ...\n"<< connectString;
session.connect(); // establish connection
cout<<"Connected\n";

/*dataset.setSQL("SELECT * FROM tbl_content_mis");

dataset.setCached(true); // noncached mode
dataset.setFetchRows(10);

cout<<"\nOpening ...\n"<< dataset.SQL();
dataset.open(); // query result rows
cout<<"Opened\n\n";

cout<<"Fetching...\n\n";
char* str;
while (!dataset.isEOF()) {
//printf("DeptNo: %-4s DName: %-15s Loc: %s\n",
cout << "hi";
cout<< dataset.field("site_id").getString()< //printf("DeptNo: %-4s DName: %-15s Loc: %s\n",
//dataset.field("con_id").getString();
// dataset.field("Loc").getString());
recordCount++;
dataset.next(); // go to next record
}

cout<<"\nFetched:\n";
cout<<" - rows\n"<< recordCount;
if (dataset.isCached())
cout<< "-cached\n";
else
cout<<" - no cached\n";
cout<<" - fetch rows: \n"<< dataset.fetchRows();

dataset.close(); */

session.disconnect(); // close connection
cout<<"\nDisconnected\n\n";

}
catch (CCRException& E) {
cout<<"Error: %s\n"<< E.message();
}

//cout<<"Press ENTER to exit\n";
//getchar();
//getch();

return 0;
}

You have too do some settings with c++......
Oracle Connectivity with C++
1. Keep the OCL (Oracle Class Library) in oracle\product\10.2.0\db_1\ directory.
2. Include OCI include folder in visual studio project.

3. Include OCL include folder in visual studio project.

4. Include Library files of OCI directory and also include all the folders of which are inside the LIB folder.

5. Include BC and MSVC folder of OCI inside the library files.

6. Include OCL\LIB folder inside library files.
7. Include OCL\LIB\BCB\ folder inside library files.
8. Include OCL\LIB\GNU\ folder inside library files.
9. Include OCL\LIB\MSVC\ folder inside library files.

10. Link the library files into project settings.

11. Write oracore8.lib (for oracle 8i) oraocci10d.lib (for oracle 10g for debug module), ocl.lib oci.lib or oci_w32.lib into object/library modules.
12. Include oraocci10.lib for release module.


For any clearification just comment the question.........

All the best........ :)