Connecting to an Oracle Spatial Database
Connecting to an Oracle Spatial Database
The following code sample illustrates connecting to an Oracle database and adding custom reactors.
Custom reactor declarations are in MyMapOracleReactors.h, one of the files included at the beginning of the sample. The "Subclassing Custom Reactors" sample shows what such a file would contain.
Managing the Connection (Overview) Subclassing Custom Reactors (Sample) Other Related Samples
#include "StdAfx.h"
#include "StdArx.h"
#include "AdMapOracleConnection.h"
#include "MyMapOracleReactors.h" // Custom reactors
BOOL ConnectToOracle(){// Get connection pointerAcMapOSEConnection *pConnection = AcMapOSEGetConnection();// Initialize reactorsMyConnectionReactor *pConnectReactor = new MyConnectionReactor();MyExportReactor *pExportReactor = new MyExportReactor();MyImportReactor *pImportReactor = new MyImportReactor();// Add reactors to connection objectpConnection->AddConnectionReactor(pConnectReactor);pConnection->AddExportReactor(pExportReactor);pConnection->AddImportReactor(pImportReactor);// Make the connectionBOOL bConnect = FALSE;if(!pConnection->IsConnected()){bConnect = pConnection->Connect("Scott", "TestDB", "Scott", "Tiger", false);}else{acutPrintf("Already connected to Oracle!");return FALSE;}// Check for valid connection using various diagnostic functions// Check if schema is valid()if(pConnection->IsSchemaValid()){acutPrintf("\nSchema is valid for this connection\n");}else{acutPrintf("\nSchema is not valid\n");}// Get the latest state of the Oracle database if it has been// changed since the connection was madeif(pConnection->RefreshSchema()){acutPrintf("\nSchema refreshed\n");}else{acutPrintf("\nError refreshing schema\n"):}// Get a list of the feature names in the current schemastd::vector<std::string> vFeatureNames;if(pConnection->Features(vFeatureNames)){acutPrintf("\nGot feature names\n");}else{acutPrintf("\nError getting feature names\n");}// Get the service namechar *pService = 0;pSerive = new char[80];strcpy(pService, pConnection->Service());acutPritnf("\nService is %s\n",pService);delete [] pService;// Get the schema namechar *pSchema = 0;pschema = new char[80];strcpy(pSchema,pConnection->Schema());acutPritnf("\nSchema is %s\n",pSchema);delete [] pSchema;// Get the user namechar *pUserName = 0;pUserName = new char[80];strcpy(pUserName,pConnection->UserName());acutPritnf("\nUserName is %s\n",pUserName);delete [] pUserName;// Break the connectionif(pConnection->Disconnect())acutPritnf("\nDisconnected from Oracle\n");elseacutPritnf("\nError disconnecting from Oracle\n");// Remove reactors from connection interfacepConnection->RemoveConnectionReactor(pConnectReactor);pConnection->RemoveExportReactor(pExportReactor);pConnection->RemoveImportReactor(pImportReactor);delete pConnectReactordelete pExportReactordelete pImportReactor}