Global Data Management Forum

 View Only

 Net.IBM.Data.Db2-lnx throws exception. 'System.DllNotFoundException' in IBM.Data.Db2.dll

Kris Fraley's profile image
Kris Fraley posted Fri April 11, 2025 10:39 AM

Below is my .NET (C#) code snippet  running on Debian 11 (bullseye) on top of Linux kernel version 5.10.113 #34 that's throwing the "'System.DllNotFoundException' in IBM.Data.Db2.dll" exception. The code is running on .NET 6.  I've tried using both of the following ODBC CLI drivers: v11.5.9_linuxx64_odbc_cli.tar.gz and v12.1.1_linuxx64_odbc_cli.tar.gz.

public override string ValidateConnection()
{
    fullConnectionString = GetConnectionString();        // fullConnectionString = Server=<<IP-address>>:25000; Database=SAMPLE; UID=db2admin; PWD=db2admin; Max Pool Size=100;

    using (DB2Connection conn = new DB2Connection(fullConnectionString))        // exception thrown in the new DB2Connection(fullConnectionString)
    { ... }
}

The exception Message is...
"Unable to load shared library 'libdb2.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdb2.so: cannot open shared object file: No such file or directory"

The exception StackTrace is...
   at IBM.Data.Db2.UnsafeNativeMethods.DB232.SQLFreeConnAttribsADONET(DB2SQLGetConnAttribsADONETParams& pParam)
   at IBM.Data.Db2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDownStrAppended)
   at IBM.Data.Db2.DB2Connection.set_ConnectionString(String value)
   at IBM.Data.Db2.DB2Connection..ctor(String connectionString)
   at OLDI.xATM.EditModel.Adapters.DB2Adapter.ValidateConnection() in <<my-source-path>>\DB2Adapter.cs:line 177

My environment variables are set as follows...
export DB2_CLI_DRIVER_INSTALL_PATH=$HOME/db2_cli_odbc_driver/odbc_cli/clidriver
export LD_LIBRARY_PATH=$HOME/db2_cli_odbc_driver/odbc_cli/clidriver/lib
export LIBPATH=$HOME/db2_cli_odbc_driver/odbc_cli/clidriver/lib
export PATH=$HOME/db2_cli_odbc_driver/odbc_cli/clidriver/bin:$PATH
export PATH=$HOME/db2_cli_odbc_driver/odbc_cli/clidriver/adm:$PATH

Per the suggestion in the exception Message, I have used...
root@KFtManager56:/root/db2_cli_odbc_driver/odbc_cli/clidriver/lib# LD_DEBUG=libs ldd libdb2.so.1
The output of the command line appears to be completely error free (see attachment).

My system appears to have all it needs to handle what I'm trying to accomplish.  Can anyone help me rectify this problem???

Thanks for reading. Please reply.
-Kris


Attachment  View in library
output.txt 24 KB