For a .Net C# app that uses SAP.DATA.HANA.v4.5
v2.3.119 and is installed on the runtime machine with the libadonetHDB.dll
v2.3.119 with the environment variable HDBADONET
pointing to the app folder where libadonetHDB.dll
exists. The application works as expected so far on several installations, however one new installation I am seeing it fail producing the The specified module could not be found error exception from HanaConnection below:
The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception.
System.Exception: The specified module could not be found
at Sap.Data.Hana.HanaUnmanagedDll.LoadDll(String dllPath)
at Sap.Data.Hana.HanaUnmanagedDll..ctor()
at Sap.Data.Hana.HanaUnmanagedDll.get_Instance()
at Sap.Data.Hana.HanaConnection..cctor()
Also tried just moving the dll to the same folder where the application is installed and the same results are produced.
According to the documentation, the dll being in the same folder as the application or via the HDBADONET
environment variable path location should work (and have experienced it working on several other installations). This is part of the general workflow for developing and using the ADO.NET library for non-native .NET apps documented here
I've been trying this as the "Administrator" user and this is a brand new Virtual Machine created (tried both new Windows10 x64 VM and new Windows Server 2016 x64 VM). Also confirmed .NET v4.5+ was installed.
Is it possible that a machine can have a permissions or other policy that affects loading of dlls?
Any clue as to why the SAP Hana ADO.NET DB Connection DLL loading will fail but not in all cases?
Is the libadonetHDB.dll
still trying to find and load libSQLDBCHDB.dll
or another dll on the machine for some reason? It has been my understanding that using the ADO.NET DLL allowed the machine to not need the other client installation and dlls installed.
Which module
is it that can't be found specifically? Is there a way to get the Hana Connection DLL loading to generate more verbose output when it fails?
Update
To confirm that the libadonetHDB.dll
is actually found using the HDBADONET
environment variable definition, I removed the file and retested and I get a different message:
The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception.
System.IO.FileNotFoundException: Cannot find a matching libadonetHDB.dll
with version 2.3.119 - check the location in the HDBADONET or PATH
environment variables
at Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls()
at Sap.Data.Hana.HanaUnmanagedDll..ctor()
at Sap.Data.Hana.HanaUnmanagedDll.get_Instance()
at Sap.Data.Hana.HanaConnection..cctor()
So, the message posted in the original post is coming after libadonetHDB.dll
has been found successfully. So it seems like the complaint in the exception message about unable to find or load a module is referring to some other resource or dll it is looking for, but the message is not verbose enough to know what that is. Any ideas?
Update (the solution)
The short answer:
Inspecting libadonetHDB.dll
with Dependencies reveals that msvcr100.dll
and msvcp100.dll
were both missing on the runtime machine for some reason. Adding those missing DLLs to the app's installation package resolved the issue.
The longer answer:
Thanks to donjuedo for suggesting to interrogate the DLL to see its dependencies. The tool I used on the machine where it was failing is Dependencies (which requires installation of vc++ redistributable x64 as noted in the readme for it to work) revealed that msvcr100.dll
and msvcp100.dll
were both missing as dependencies when inspecting libadonetHDB.dll
. Note that they were only found to be missing on this particular machine which was a freshly created virtual machine so the inspection and test case had to happen on that machine.
The solution for including the missing DLLs at installation time can be to add msvcr100.dll
and msvcp100.dll
to either of the following locations:
C:\Windows\System32
(probably not a preferred solution if you want your app to avoid installing things into the main system folder)- the folder where the app's exe also exists
- an app's lib subfolder so long as you add the path to that subfolder to the
PATH
environment variable definition (i.e.set PATH=%PATH%;fullpath\to\app\lib
)
These two dlls were already on our development machine and are likely already part of many runtime/client machines that have been around a while and have had other software that needed them. If you don't have these around even in development then download them from Microsoft's official packages as noted here (avoid getting them from 3rd party dll websites if you want be sure they aren't malware hiding in a dll). Ideally the documentation for the SAP HanaDB ADO.NET library should mention the requirements of the runtime machine or that the .NET developer needs to provide these dependent DLLs.