Error with embedded connection in C++ application on Linux

117 views
Skip to first unread message

Margaret Lawson

unread,
Mar 1, 2021, 3:52:57 PM3/1/21
to firebird-support

I am attempting to create an embedded firebird 3.0 database in a C++ application on a linux machine. I have followed the directions found here: https://wiki.freepascal.org/Firebird_embedded#Creating_the_test_database . However, I receive a "Failed to establish a connection" error.

Following these directions, I have created a firebird.config file in my project home directory containing:
Providers = Engine12
RootDirectory=/path/to/proj/home/dir/firebird
DatabaseAccess = Full
ExternalFileAccess = Full
UdfAccess = Full

Where /path/to/proj/home/dir is filled in with the appropriate value.

In my project home directory, I have created a firebird directory containing libfbclient.so, and a plugins directory containing libEngine13.so. I have done:
export LD_LIBRARY_PATH=/path/to/proj/home/dir/firebird
export FIREBIRD=/path/to/proj/home/dir

I have built my example using CMake and linked to both libfbclient and libEngine13. My example, which merely attempts to create a database, contains the following:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>

#include <iostream>

int pr_error (long *, char *);


int main (int argc, char** argv)
{
    isc_db_handle   newdb = NULL;          /* database handle */
    isc_tr_handle   trans = NULL;          /* transaction handle */
    ISC_STATUS_ARRAY status;               /* status vector */
    long            sqlcode;               /* SQLCODE  */
    char            create_db[160];        /* 'create database' statement */
    char            new_dbname[128] = "/path/to/proj/directory/new.fdb";

    sprintf(create_db, "CREATE DATABASE '%s'", new_dbname);

    if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, 1,
                                   NULL))
    {
        sqlcode = isc_sqlcode(status);

        if (sqlcode == -902)
        {
            printf("\nDatabase already exists.\n");
            printf("Remove %s before running this program.\n\n", new_dbname);
        }
        if (pr_error(status, "create database"))
            return 1;
    }
    return 0;
}           


int pr_error (long* status, char* operation)
{
    printf("[\n");
    printf("PROBLEM ON \"%s\".\n", operation);

    isc_print_status(status);

    printf("SQLCODE:%d\n", isc_sqlcode(status));

    printf("]\n");

    return 1;
}

I receive the following:
PROBLEM ON "create database".
Unable to complete network request to host "my_ip_address". //where my_ip_address is filled in with the appropriate value
-Failed to establish a connection.
SQLCODE:-902

Any ideas why it is using a network connection? I should add I do not have sudo access on this machine or write permissions for root folders such as /tmp, etc. Also, since I am using cmake, the executable is not found in my project home directory (although, my firebird.config and LD_LIBRARY_PATH and FIREBIRD vars contain absolute paths, so I don't think this is the problem).

Jim McNamara

unread,
Mar 1, 2021, 7:04:54 PM3/1/21
to firebird...@googlegroups.com
HI Margaret-

If you are interested, why not try to use U++ firebird driver in "bazaar" at ultimatepp.com. It is way cooler than the other code quoted below. That is of course if you have the time and you have no reason why you have to approach the code a certain way.  I had more success with postgresql at U++ but am back to studying firebird again now. The C++ coders at U++ are amazing.

robo-loki

Virus-free. www.avg.com

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/395084a5-7b51-4dae-afa8-89b8eae1587an%40googlegroups.com.

Virus-free. www.avg.com

Mark Rotteveel

unread,
Mar 2, 2021, 7:26:30 AM3/2/21
to firebird...@googlegroups.com
On 2021-03-01 21:52, Margaret Lawson wrote:
> I am attempting to create an embedded firebird 3.0 database in a C++
> application on a linux machine. I have followed the directions found
> here:

> I receive the following:
> PROBLEM ON "create database".
> Unable to complete network request to host "my_ip_address". //where
> my_ip_address is filled in with the appropriate value
> -Failed to establish a connection.
> SQLCODE:-902

This would suggest that your application is using a libfbclient that
doesn't have access to the embedded engine (plugins/libengine12.so), and
therefor falls back to a remote connection.

Mark

Scott Morgan

unread,
Mar 2, 2021, 7:47:05 AM3/2/21
to firebird...@googlegroups.com
On 01/03/2021 20:52, Margaret Lawson wrote:
>
> I am attempting to create an embedded firebird 3.0 database in a C++
> application on a linux machine.
...
>     if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, 1,
>                                    NULL))


As an aside, not really a solution to your main problem, but do you
really want a dialect 1 DB?

Scott

Steve Naidamast

unread,
Mar 2, 2021, 10:43:32 AM3/2/21
to firebird...@googlegroups.com
Margaret...

I do not know if you have the attached paper by Helen Borrie but she is one of the lead developers on the Firebird Database.  Helen Borrie wrote this paper specifically for those who are planning on using the Version 3.0 Firebird Embedded Database.

It may help resolve your issue...

Steve Naidamast
Sr. Software Engineer


From: firebird...@googlegroups.com <firebird...@googlegroups.com> on behalf of Margaret Lawson <mlaw...@gmail.com>
Sent: Monday, March 1, 2021 3:52 PM
To: firebird-support <firebird...@googlegroups.com>
Subject: [firebird-support] Error with embedded connection in C++ application on Linux
 
Embedded_fb3.0.pdf

Margaret Lawson

unread,
Mar 2, 2021, 1:59:44 PM3/2/21
to firebird-support
Thank you all for your replies.

I agree. This indicates it is not able to find plugins/libengine12.so (or libengine13.so in my case), but I do not understand why.

Things I have tried:
When building with CMake (I have tried basically all possible subsets of the following steps, just in case):
-linking the libengine13.so library
-having a folder containing libfbclient.so (and all related libraries) and libengine13.so and plugins/ibengine13.so (and just in case, when this failed I tried copying libengine13.so to libengine12.so and plugins/libengine12.so)
-adding the folder to LD_LIBRARY_PATH
-export FIREBIRD=/path/to/this/folder
-in firebird.conf: explicitly setting RootDirectory to /path/to/this/folder, Providers = Engine13 and ServerMode = Classic

When using the ODBC:
-having a folder containing libfbclient.so (and all related libraries) and libengine13.so and plugins/libengine13.so (and just in case, when this failed I tried copying libengine13.so to libengine12.so and plugins/libengine12.so)
-adding the folder to LD_LIBRARY_PATH along with the odbc library

And thank you for the paper. I have seen it before, but it's a good suggestion. Since I got my code from git my file structure doesn't resemble the one described in the paper, but I also tried creating a bare bones folder with the contents described in the paper and that didn't work either.

Is there anything else I can try or am missing?

Steve Naidamast

unread,
Mar 2, 2021, 2:47:14 PM3/2/21
to firebird...@googlegroups.com
Margaret:

Have you tried just creating a Firebird Database simply with ISQL or DB Manager?  If so, have you been successful, using the same, in opening the database?

Steve Naidamast
Sr. Software Engineer
Sent: Tuesday, March 2, 2021 1:20 PM
To: firebird-support <firebird...@googlegroups.com>
Subject: Re: [firebird-support] Error with embedded connection in C++ application on Linux
 

Margaret Lawson

unread,
Mar 2, 2021, 3:01:55 PM3/2/21
to firebird-support
Hi Steve,

When I try using the ODBC's isql I get:
[08004][unixODBC][ODBC Firebird Driver]Unable to complete network request to host "xxxIpAddrxxx".
Failed to establish a connection.
[ISQL]ERROR: Could not SQLConnect

When I use the isql from firebird I get the similar message of:
Statement failed, SQLSTATE = 08006
Unable to complete network request to host "localhost".

-Failed to establish a connection.
On Tuesday, March 2, 2021 at 11:47:14 AM UTC-8 blackfalc...@ix.netcom.com wrote:
Margaret:

Have you tried just creating a Firebird Database simply with ISQL or DB Manager?  If so, have you been successful, using the same, in opening the database?

Steve Naidamast
Sr. Software Engineer

Dimitry Sibiryakov

unread,
Mar 2, 2021, 3:06:53 PM3/2/21
to firebird...@googlegroups.com
02.03.2021 19:20, Margaret Lawson wrote:
> Things I have tried:

You should try to use strace to find out where the engine plugin is looked for and why
it cannot be found.

--
WBR, SD.

Margaret Lawson

unread,
Mar 2, 2021, 3:51:02 PM3/2/21
to firebird-support
Thanks! I didn't know about strace. Using it I was able to figure out that isql was looking for libEngine in /path/to/firebird/install, and was able to copy it there and get it to connect.

Using strace I was also able to confirm that my CMake example was able to find libEngine in the expected /plugins directory, but was still giving me the same error. I switched the database location to the parallel file system (rather than my home directory) and it worked. The two folders have the exact same access permissions, so not quite sure why that is. Maybe some POSIX issue? But the parallel file system is where I would want to store the database anyways, so this is good enough.

Thank you very much for your help!

Dimitry Sibiryakov

unread,
Mar 2, 2021, 5:20:55 PM3/2/21
to firebird...@googlegroups.com
02.03.2021 21:39, Margaret Lawson wrote:
> Thanks! I didn't know about strace.

It was mentioned in the first comment to your question on Stack Overflow.

--
WBR, SD.

Mark Rotteveel

unread,
Mar 3, 2021, 11:55:33 AM3/3/21
to firebird...@googlegroups.com
On 01-03-2021 21:52, Margaret Lawson wrote:
> I am attempting to create an embedded firebird 3.0 database in a C++
> application on a linux machine. I have followed the directions found
> here:
> https://wiki.freepascal.org/Firebird_embedded#Creating_the_test_database
> . However, I receive a "Failed to establish a connection" error.
>
> Following these directions, I have created a firebird.config file in my
> project home directory containing:
> Providers = Engine12
[..]
> In my project home directory, I have created a firebird directory
> containing libfbclient.so, and a plugins directory containing
> libEngine13.so. I have done:

Your firebird.conf specifies *Engine12*, so it won't load *Engine13*.

As I also pointed out on Stack Overflow, libengine13.so would be for
Firebird 4 (On-Disk Structure (ODS) 13) databases, not for Firebird 3
(ODS 12) databases. Given you're using Firebird 3, why have you built
something called libengine13.so?

Mark
--
Mark Rotteveel

Margaret Lawson

unread,
Mar 3, 2021, 2:11:59 PM3/3/21
to firebird-support
I tried both Engine12 and Engine13 in the config (and had copied libEngine13.so to libEngine12.so as well for good measure).

But yes, Engine13 vs Engine12 was a good catch (that I wasn't aware of). I cloned from git and saw 3.0.7 was the latest release, and didn't check any further, which was a mistake on my part. What was cloned was release candidate 1 for  firebird 4. But in any case, I'm just glad it's working. I then tried cloning 3.0.7 (and 3.0.6) and ran into a double free error when building. So unless you would recommend I not use it, I would just plan to use firebird 4.
Reply all
Reply to author
Forward
0 new messages