Skip to content

pyinstaller builds - <built-in function connect> returned NULL without setting an exception #1040

@BotBlake

Description

@BotBlake

Description

This issue is simmilar to the closed issues #294 and #886!
Since both of them do not contain any solution for this, I am opening a new one.

Using ibm_db normaly works fine. Bundling it in a pyinstaller .exe-build, it throws the following Error:
<built-in function connect> returned NULL without setting an exception

Steps to Reproduce:

  1. use ibm_db.connect(database, username, password) somewhere in your script (script.py)
  2. bundle script into .exe-File via pyinstaller ./script.py
  3. run script.exe -> Observe Error

Sadly, even when attaching additional debug statements to the script, this is the only Error message I am abled to find.
On one of the other two issues, I saw someone asking for the output of db2trc from reproducing this error - I have attached the trc.flw below.

Test Scripts

main.py - just connecting to the Database.

import creds # Local file containing password, username and database-name
import os, logging, locale, traceback

locale.setlocale(locale.LC_ALL, "de_de")
logging.basicConfig(level=logging.DEBUG)

dll_path = r"C:\Program Files\IBM\SQLLIB_RTC_115\BIN"
os.add_dll_directory(dll_path)
import ibm_db

print(f"Testing DLL Folder {os.path.exists(dll_path)}")

try:
    print("Normal Connect")
    db_connection = ibm_db.connect(creds.database, creds.username, creds.password)
    print("Connected...")
    print(f"1: {ibm_db.conn_error(db_connection)}")
    print(f"2: {ibm_db.conn_errormsg(db_connection)}")
except Exception as e:
    traceback.print_exc()
    traceback.print_exception(e)
    print(e)

-> running main.py directly works fine.

build.py

import subprocess

pyinstaller_command = [
        "pyinstaller", "--onefile",
        "--name", "test",
        "./main.py",
        "--console", "--debug", "all"
    ]

subprocess.run(pyinstaller_command)

Running test.exe (in a shell, even with admin) outputs:
<built-in function connect> returned NULL without setting an exception
Whilst I am running pyinstaller in --onefile mode, the error also reproduces just fine without!

Environment

  • Operating System Name: Windows
  • db2level output from clidriver if in use:
DB21085I  This instance or install (instance name, where applicable: "DB2")
uses "64" bits and DB2 code release "SQL11059" with level identifier
"060A010F".
Informational tokens are "DB2 v11.5.9000.352", "s2310270807",
"DYN2310270807WIN64", and Fix Pack "0".
Product is installed at "C:\PROGRA~1\IBM\SQLLIB~1" with DB2 Copy Name
"DB2_RTC_115".
  • Target Db2 Server Version: DB2 z/OS 13.1.7
  • Python Version: 3.13.7
  • ibm_db version: 3.2.8
  • Value of below environment variables if set:
    None (see code example)

Additional

logging the trace output of the db2 clidriver, you get the following information:

<db2trc_header>
Marker                  :  @TRACE@
Trace version           :      7.0
Platform                : NT 64BIT
Build level             : s2310270807
maxBufferSize           : 2097152 bytes (2 MB)
auxBufferSize           : 0 bytes (0 MB)
allocationCount         : 0
DB2TRCD pid             : 1
Trace destination       : trc.dmp
numSuspended            : 0
Trace starting time     : 2025-12-11-09.58.57.212000+060
Trace status            : UNKNOWN
Trace status change time: N/A
Buffer size             : 2097152 bytes (2 MB)
Allow buffer to wrap    : yes
Mask                    : *.*.*.*.*
Timestamps              : disabled
PID.TID mask            : all
Fixed data mask #1      : all
Fixed data mask #2      : all
Max system errors       : infinite
Treat this rc as sys err: none
sqlcodes for stoptrc    :  none
Search Pattern          : none
clitracelevel           : none
Member mask             : none
Application handle mask : none
Application ID mask     : none

</db2trc_header>

pid = 4720 tid = 4724 node = 0

1           sqloMgmtServiceCtrlHandler entry
2           | ReportServiceStatus_DB2MGMTSVC entry
3           | ReportServiceStatus_DB2MGMTSVC exit [rc = 1]
4           sqloMgmtServiceCtrlHandler exit
5           sqloMgmtServiceCtrlHandler entry
6           | ReportServiceStatus_DB2MGMTSVC entry
7           | ReportServiceStatus_DB2MGMTSVC exit [rc = 1]
8           sqloMgmtServiceCtrlHandler exit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions