Connect ODBC without driver installed

喜欢而已 提交于 2020-01-25 04:17:27

问题


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


回答1:


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...




回答2:


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.


来源:https://stackoverflow.com/questions/54826254/connect-odbc-without-driver-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!