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
        // connect to database (in this example it is SQL Server)
            "demo",     // database name
            "guest",    // user name
            "secret",   // password

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

        // Disconnect is optional
        // auto disconnect will occur in destructor if needed

        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
            // on error rollback changes
        catch(SAException &)
        // print error message
        printf("%s\n", (const char*)x.ErrText());
    return 0;
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.