How to register ODBC driver?

此生再无相见时 提交于 2019-12-19 09:18:21

问题


I have created a inventory system for my school project and I use SqlLite as standalone DB. I am able to run it as long as I install the SqlLite ODBC connection (separate installer).

But what I want is to create an installer and install the SqlLite ODBC Drivers along with my porject in one installer instead of of running two separate installer (my application and sqlLite ODBC driver installer).

Any idea how to do it? Or do you have any recommendation?

What I have done so far. I copy the SQLLite ODBC dll into my application folder and run it but an error shows telling that no ODBC driver installed. I failed to register the SqlLite odbc dll on both 32 and 64 bit windows OS.


回答1:


What I would recommend for you is to create a bootstrapper installation package. You didn't mention the platform you are delivering for, but since you are writing about installers I will assume that the platform is Windows.

There are multiple installer frameworks you can use to create installers for your software on Windows, but the one I recently used and would recommend is WixToolset. They have some documentation on how to build bootstrapper bundles here

In great simplicity my wix bootstrapper came down to installing one exe installer and one msi installer and the configuration looked something like this (in great simplicity - the link I provided has full documentation on how to configure all the features)

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"       xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
   <Bundle Version="..." Name="...">
        <Chain>
            <ExePackage Id = "x86redist" SourceFile="..." ... />
            <MsiPackage Id = "myApp" SourceFile ="..." ... />
        </Chain>
  </Bundle>
</Wix>

in the end after building, my bootstrapper bundle looked like this

and made sure both my software and the redistributable package were installed on the machine when it was finished.

You could use exactly the same approach - the bundle could install the odbc driver using its original installer, and then install your software.




回答2:


It was difficult to find, so i'm going to add it as an answer here on Stackoverflow. I knew the answer from spelunking the registry, but i wanted the supported method.

From Registry Entries for ODBC Components, we learn ODBC drivers are registered in the registry.

  • HKEY_LOCAL_MACHINE
    • SOFTWARE
      • ODBC
        • Odbcinst.ini
          • ODBC Drivers

will contain a value for each driver equal to "Installed":

So you would need to create something like:

HKLM\SOFTWARE\ODBC\Odbcinst.ini\ODBC Drivers
    "SqlLite": REG_SZ = "Installed"

For each driver, there will then exist an

  • HKEY_LOCAL_MACHINE
    • SOFTWARE
      • ODBC
        • Odbcinst.ini
          • [Driver name]

In this folder is a series of Driver specifications:

Microsoft documents these items quite nicely in the Driver Specification Subkeys page on MSDN.

In the case of an SqlLite ODBC driver that would mean there is a key called:

HKLM\SOFTWARE\ODBC\Odbcinst.ini\SqlLite

and you would have to be sure to create all the values for the SqlLite ODBC driver.

But don't do that

Another item in the driver details is a reference count (called UsageCount). This Usage Count is not meant to be fiddled with by people; but instead is updated when you call the functions:

  • SQLInstallDriverEx
  • SQLRemoveDriver

So while you can push stuff into the registry yourself, you should be calling the documented API SQLInstallDriver.

And while it's probably safe to read the registry to see what drivers are installed, the documented say to get the list of drivers is:

  • SQLGetInstalledDrivers



回答3:


You can use the odbcconf command to register the driver dll directly. Note there're both 32 bit and 64 bit ODBC drivers, so you will need to use the respective odbcconf command.

For example to install 64 bit ODBC driver on 64 bit machine:

odbcconf /A {INSTALLDRIVER "My Driver Name|driver=Path to my driver dll"}

To install the 32 bit driver on 64 bit machine:

%systemroot%/systemwow64/odbcconf /A {INSTALLDRIVER "My Driver Name|driver=Path to my driver dll"}

You can find more about the odbcconf command at Microsoft Docs



来源:https://stackoverflow.com/questions/23648252/how-to-register-odbc-driver

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