1

I wrote an example application in C++(on Eclipse Luna) using sqlapi++ libraries to connect to an Oracle database I created with sqldeveloper. The program compiles without errors, but when I run it,nothing appears on the console.

(I am using Windows 7)

Here the Database information:
Database name:"DB Casa Editrice"
Host:localhost
SID:xe
Port:1521

And the code:

#include <iostream>
#include "SQLAPI.h"
using namespace std;

int main() {
    SAConnection con; // create connection object

    try {
        con.Connect( "DB Casa Editrice",     // database name
                     "system",   // user name
                     "shruikan94",   // password
                     SA_Oracle_Client );

        cout << "We are connected!\n";
        con.Disconnect();
        cout << "Disconnected!\n";
    }
    catch( SAException &x )
    {
        // SAConnection::Rollback()
        // can also throw an exception
        // (if a network error for example),
        // we will be ready
        try {
            // on error rollback changes
            con.Rollback();
        }
        catch( SAException & )
        {
        }
        // print error message
        cout << "ERROR\n";
    }
    return 0;
}
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
aldoalpha
  • 163
  • 10
  • You are never flushing the output to stdout; you should consider using a std::endl instead of embedded '\n' somewhere, or using std::flush... Separately, have you tried using a debugger to see if you get past the connect attempt? What have you tried? – UpAndAdam Dec 11 '14 at 16:43
  • I used the debugger,and the application terminates just after i run it,with exit value -1073741515. I think there's a problem with the connection to the database,or maybe with the way I wrote the database information in the con.Connect method. – aldoalpha Dec 11 '14 at 17:10
  • It is 99,9% wrong connection string. Check how to write it here - http://www.connectionstrings.com/oracle/. – SChepurin Dec 11 '14 at 17:55
  • Can't find any specific solution on that page,thanks anyway. – aldoalpha Dec 11 '14 at 18:08
  • First, isolate the errors. Try to get connected like explained here -http://www.thetechgame.com/Archives/p=16258091.html. – SChepurin Dec 12 '14 at 08:17
  • The code in that page is nearly the same :i always have the problem about connection string (database name) that in my case is different from that example. Anyway i'll give it another try.Looking at the libraries,i just added libsqlapiddl.a :maybe i have to add something more? – aldoalpha Dec 12 '14 at 08:38
  • I didn't use sqlapi++, but the problems are generally the same with almost every DB - find/know correct connection string (could be hard). Then, work with your main code, which is easy :) – SChepurin Dec 12 '14 at 09:32
  • "maybe i have to add something more?"- If it compiles without errors, and doesn't output linking error messages, then you don't need more libraries (at least, for now). – SChepurin Dec 12 '14 at 10:18
  • Which set of libraries have you used? – aldoalpha Dec 12 '14 at 10:19

0 Answers0