1

Is it possible to make ODBC connection without system-wide driver installed? Can I just point a DLL that contains the driver?

I use it in C++, 32bit, currently testing on Windows, and connect to the Firebird Database. I tried following connection string, that doesn't work:

constexpr auto DatabaseConnection =
//"DRIVER=Firebird/InterBase(r) driver;" //this works when driver installed
"UID=SYSDBA;"
"PWD=masterkey;"
"DBNAME=C:\\some\\path\\to\\database\\DB.FDB;"
"Client=C:\\Windows\\System32\\OdbcFb.dll;";

The error message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Mariusz Jaskółka
  • 4,137
  • 2
  • 21
  • 47

2 Answers2

2

Yes, a DSN-less connection can be made to an un-registered ODBC Driver, by fully specifying the connect string.

This line, as used when the driver is installed properly --

"DRIVER=Firebird/InterBase(r) driver;"

-- which really should be this, to reference the driver by name --

"DRIVER={Firebird/InterBase(r) driver};"

-- should be changed to this --

"DRIVER=C:\\Windows\\System32\\OdbcFb.dll;"

It appears that if the %PATH% is not set correctly (to include the directory containing the odbcfb.dll) and/or if the FB driver is not registered with the MDAC driver manager, you must include the FB-specific client keyword pointing to the odbcfb.dll, in which case you should not need any reference to odbcfb.lib.

You may benefit from reading the driver's own documentation for creating DSNs and for DNSless connections...

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • setting path in Driver doesn't take any effect. The same error is displayed. I read somewhere that specifying driver path doesn't work on Windows. – Mariusz Jaskółka Feb 25 '19 at 07:55
  • Here: https://stackoverflow.com/questions/40263138/is-it-possible-to-specify-the-driver-dll-directly-in-the-odbc-connection-string – Mariusz Jaskółka Feb 25 '19 at 07:56
  • 1
    @jaskmar - I've just posted an answer to that other question, which came to erroneous conclusion. (Simply, `Driver=C:/path/to/driver/library` works fine on Windows.) – TallTed Feb 25 '19 at 14:47
  • I don't know if it is specific for Firebird, but giving path will not work without linking `OdbcFb.lib`. – Mariusz Jaskółka Feb 26 '19 at 07:00
0

Firebird ODBC Driver contains small static library (named OdbcFb.lib) that should be linked within the application. Under the hood it probably preloads the dll and registers it as a new driver somehow. When such library is linked, the connection string that works is:

"DRIVER=OdbcFb.dll;UID=SYSDBA;PWD=masterkey;DBNAME=127.0.0.1:C:\\path\\DB.GDB;";

What surprised me, when you omit DRIVER it also works, choosing apriopriate driver by using some magic:

"UID=SYSDBA;PWD=masterkey;DBNAME=127.0.0.1:C:\\path\\DB.GDB;";

Note that:

  • the OdbcFb.dll has to be visible for your application (be at the same directory or in system PATH)
  • one should be aware of choosing apriopriate library architecture, namely 32-bit or 64-bit.
Mariusz Jaskółka
  • 4,137
  • 2
  • 21
  • 47
  • The magic is (very probably) `FileExtns` (details at [Microsoft Docs](https://learn.microsoft.com/en-us/sql/odbc/reference/install/driver-specification-subkeys)) which is [set](https://github.com/FirebirdSQL/firebird-odbc-driver/blob/master/SetupAttributes.h) to `*.fdb,*.gdb` – AntoineL Jan 22 '21 at 10:23