How do you connect an Oracle database in C? |
[Edit] |
Answer
The following example creates an OracleConnection and sets some of its properties in the connection string.
- Syntax based on .NET Framework version 1.1 **
#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
using namespace System;
using namespace System::Data;
using namespace System::Data::OracleClient;
__gc class COracleConnection<br>
{
public:<br>
void CreateOracleConnection( ) <br>
{
String* myConnString Oracle8i;Integrated Security new OracleConnection( myConnString );
myConnection->Open( );
MessageBox::Show( String::Format( S"ServerVersion: {0}\nDataSource:{1}",
myConnection->ServerVersion,
myConnection->DataSource )
);
myConnection->Close();
}
};
// This is the entry point for this application
#ifdef _UNICODE
int wmain( void )
#else
int main( void )
#endif
{
COracleConnection *pCOracleConnection = new COracleConnection();
pCOracleConnection->CreateOracleConnection( );
return 0;
}
Answer
You will use Oracle's API. Its called OCI for Oracle Call Interface -- use Google for details about its usage. You can also use OTL, which is the Oracle Template Library. Its much easier to use than OCI.
Answer
Additionally, you can use embedded sql and precompile this code into pure C using the Oracle Pro*C/C++ precompiler. Sample code exists in ORACLE_HOME/precomp/demo/proc and ORACLE_HOME/rdbms/demo. As Oracle is the largest database company in the world with the largest market share of enterprise s/w, you can bet there is code all over the internet to do what you want to do. Check the forums at otn.oracle.com, google (or other search engine), or asktom.oracle.com.
First answer by ID1135109744. Last edit by Iuhoosier88. Contributor trust: 49 [recommend contributor]. Question popularity: 33 [recommend question]
|
Research your answer: |



