How to connect to Oracle in C++? - c++

I tried to connect to Oracle using C++ but it is giving me error stating that DBManger.h not found. I have also tried using occi.h but got the same error of not found or No Such Directory.
I have installed Oracle 11g and it contains the OCI Liabraries also.
I located the specififc folders also where the OCI libraries are present . In my system they are at location E:\app\user\product\11.1.0\db_1\OCI\lib\MSVC\vc8.
I have also set the Path starting with Oracle home. But, still my program is not able to find the header files.
Any help would be greatly appreciated? I Googled a lot but found the same solution stating that locate the folder where the OCI libraries are available. I am posting my code below written in Visual Studio 2008:
I have written a very small script and just included the header files. Not even done the connectivity:
#include <occi.h>
#include <iostream>
using namespace oracle::occi;
using namespace std;
class DataBaseConnectionTest
{
public:
void test()
{
cout<<"Hello from test"<<'\n';
}
};
void main()
{
DataBaseConnectionTest *dbc=new DataBaseConnectionTest();
dbc->test();
}

Modify your project properties, add the E:\app...vc8 directory name to the Addition include directories. It's under C++/General. No need to double every \ in that one.
You'll probably need a similar treatment for the OCI library file anyway. The include file is only half the puzzle, the other half is the LIB.

You could consider OTL as alternative to OCI. Then your code could be more portable. I used it many years ago, interfacing SqlServer, and was surprised by the clean design and the raw speed (way faster than MFC+ODBC...). Also, I had a problem and Sergei gave me immediate assistance.

Related

Fatal Error: comdef.h: No such file or directory

I installed Aspose.Cells and tried to write a simple C++ file that includes Aspose.Cells.h. I soon realized that I had to install two other external libraries, boost and icu4c as without these libraries my compiler would throw errors saying some h or hpp files can not be found.
My problem is: even after I installed these libraries, I still couldn’t compile my code, as I received a new error saying “Fatal ERROR: comdef.h: No such file or directory.”
And the error persisted even after I installed the latest version for SDK for Win 10.
My simple file can run if I remove the line "#include Aspose.Cells.h" .
Can someone please enlighten me as to how to solve this error?
Also I noticed there is a folder called “Publish” under “include” folder for Aspose.Cells. This folder is besides boost and icu. Could this mean Publish is the third external library to be installed? But I couldn’t find any library called Public on the web. Pls see the screenshot below.
directory of include folder that comes with the installed Aspose.Cells package
Thanks a lot!
My code is as follows:
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "hello!!!" << endl;
return 0;
}
Regards
Hillary

Why does "cout" keep giving me error C1083?

I was using Visual C++ 6.0 just now, and I keep getting this error:
fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
My code is just a simple hello world program.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"Hello World.";
return 1;
}
Then I went and checked my INCLUDE folder and found a file called STREAMBF, but the compiler was looking for STREAMBUF. Notice that the file that is present is missing the U, between the B and the F. This was from a good copy of VC++6.0, directly from the actual CD, not a pirated copy. So there should be all the files needed. But it appears that a file is missing! Is this MS being stupid again, and yet making another big mistake, and forgetting to include an important file on their CDs? I'd hate to think that every single CD for VC++6.0 that was pressed that came out of MS factories had this problem. And I know that it is a missing file, not just a misnamed file, as renaming STREAMBF to STREAMBUF just led to more errors.
Anybody know where I can find a copy of the file STREAMBUF? Or am I just overlooking something here? Is this exact error a known problem with running old copies of VC++ on modern OS's like Windows 7? Is it possible that the only reason that it's looking for STREAMBUF is that this is a newer file associated with Win7, and that if it was running in a different environment (an older OS), it would actually be looking for the correct file, STREAMBF? Can somebody help me here?
Your installation is either broken, deprecated or interpretes your code in wrong way.
You should only use older compiles if you are trying to build project developed entirely for this version.
Try to compile same code with new compiler, if you want to use VS then you should look for Visual Studio Express 2013.
Your code does not have any errors.
Modify your program to, you should be able to see it okay.
#include <iostream.h>
using namespace std;
int main()
{
cout<<"Hello World.";
return 1;
}
However,
your compiler is pretty old. You need to an upgrade.
There are C++ compilers for Windows from Microsoft Express Visual Studios Link and Info VS2013 to
some other non-Microsoft like GCC for Windows.
If you don't have installation access there are some portable c++ compilers.
Finally there are some online compilers for simple test. web based online compilers.
For my win 10 installation of VC 6.0, I had the same problem ... fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
Replacing with <iostream.h> does not solve the problem.
I have checked the header file installation folder (Program files\VS98\VC98\INCLUDE). For some (unknown) reason, some file names have been changed during installation. Restoring the original name has solved the problem, in my case, in example:
Turn STREAMBF into STREAMBUF, STDXCEPT into STDEXCEPT, XCEPTION into EXCEPTION, FCTIONAL into FUNCTIONAL.
Notice: other header file names might be wrong. I have listed above the file names wrong in my installation.
I hope this may help.

Connecting VBS C++ code with SQL Server

ok so i have searched the internet for a solution but i seem to not be getting it.
im running Windows 7, 32-bit OS
i installed Microsoft SQL Server Management Studio Express 2012 with all the tools.
I created a simple database with a table and some entries.
I currently use Microsoft Visual C++ 2010 Express to design applications. I want to write a really simple application that connects to this database just to see how it works.
By the way this is all done on a one machine(localhost)
here is the c++ code:
//not sure if some of these are even needed
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <windows.h>
#include <C:\\Program Files\\Microsoft SQL Server\\110\\SDK\\Include\\sqlncli.h>
using namespace std;
int main()
{
//what would i put here?
}
What would be the simplest syntax be for the main function to connect to the SQL server?
I have linked the library file and header file in the project properties like so:
Header file Name: sqlncli.h
Project Properties - configuration properties - C/C++ - Additional Include Directories - *C:\Program Files\Microsoft SQL Server\110\SDK\Include*
Library File Name: sqlncli11.lib
this time under Linker in properties - Additional Include Directories - *C:\Program Files\Microsoft SQL Server\110\SDK\Lib\x86*
Some people mentioned a DLL but i could not find one.
So...
*I installed correct SQL package
*Created a database with a table and values
*included library and header file in C++ code
*configured properties to look for them.
Is this supposed to be this confusing or am i really missing something here?

Simple C++ program using pqxx (postgres)

I'm trying a very basic C++ program using Code::Blocks. I'm on Ubuntu 12.04 and installed pqxx from the software manager. Here's the code.
#include <pqxx/pqxx>
#include <iostream>
using namespace std;
int main()
{
pqxx::connection MyConn ("dbname=dbESM user=postgres");
cout << "Hello world!" << endl;
return 0;
}
But I get the following error on hitting F9 to compile and run:
/usr/include/pqxx/connection.hxx|87|undefined reference to
`pqxx::connectionpolicy::connectionpolicy(std::basic_string, std::allocator > const&)'
The above message is from the file connection.hxx and the line highlighted is this:
explicit connect_direct(const PGSTD::string &opts) : connectionpolicy(opts) {}
The connection.hxx file is not mine - I think it's part of pqxx.
I'm pretty new to this platform so I'm avoiding the terminal to compile code. Any help would be greatly appreciated.
You need to add the reference to the libpqxx library to the project.
Inside Code::blocks, when the project is open, locate Project in the menus, then follow Build options, then open the tab called Linker settings, then hit Add, then enter pqxx.
If you were using the libpq C library instead, the procedure would be identical except the name would be pq.
You need to link against the according library, just #including the header files isn't enough. If available, you could use pkg-config to determine the according libraries. Further, what IDE are you using? Without that, the "on hitting F9" reference is useless. Also, compiling this on the commandline might even be easier, since it is clearer what exactly is happening.

Berkeley DB(Unable to Locate Component)

I have a problem with berkeley DB. I get a dialog titled "Unable To Locate Componenent" saying "This application has failed to start because libdb48.dll was not found. Re-installing the application may fix this problem", then it crashes after clicking ok. I got the error message when running these simple code below:
#include <iostream>
#include <string>
#include <db_cxx.h>
using namespace std;
int main()
{
Db db(0, 0);
}
I already set the Additional include directories to the "build_windows" directory and I have linked to the "libdb48.lib". I honestly do not know what to do here. The funny part is, I googled and I had 0 pages returned.
I am using visual studio c++ 2008 and Berkeley DB 4.8.24
Thanks
Where is libdb48.dll? Is it installed? Where? A hackish solution that should make it work is to copy libdb48.dll into c:\windows\system32. If that solves the problem, then you know that the DLL just wasn't on the path. Then you can find a more appropriate place to put it.