When an error occurs inside SQLAPI++ Library it throws an exception of type SAException. The recommended way to process errors is to catch a reference to SAException class.

The following complete example shows a common pattern for handling library exceptions:

#include <stdio.h>  // for printf
#include <SQLAPI.h> // main SQLAPI++ header

int main(int argc, char* argv[])
{
    SAConnection con; // create connection object
    
    try
    {
        // connect to database (in this example it is SQL Server)
        con.Connect(
            "demo",     // database name
            "guest",    // user name
            "secret",   // password
            SA_SQLServer_Client);

        printf("We are connected!\n");

        // Disconnect is optional
        // auto disconnect will occur in destructor if needed
        con.Disconnect();

        printf("We are 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
        printf("%s\n", (const char*)x.ErrText());
    }
    
    return 0;
}
step1.cpp
Need Help?
Send an e-mail to support@sqlapi.com if you want to ask code-level questions, if you’re stuck with a specific error or need advise on the library best practices.