odbc icon indicating copy to clipboard operation
odbc copied to clipboard

Database connection fails due to error with SQLAllocHandle

Open lorenzbr opened this issue 1 year ago • 6 comments

Hello,

I updated R from MS R Open and R 4.0.1 to R 4.3.1. Since then, I have trouble connecting to DB2 databases via the 'odbc' package (Version 1.3.5). I get the following error (trying to translate from German):

Error: nanodbc/nanodbc.cpp:1135: IM004: [Microsoft][ODBC Driver Manager] error with SQLAllocHandle for driver on SQL_HANDLE_EN

This is the code I am using: Example:

connection <- odbc::dbConnect(
    odbc::odbc(), 
    .connection_string = paste0('DRIVER=', "{IBM DB2 ODBC DRIVER}",
        ';UID=', "username", ';PWD=', "yourpw", ';HOSTNAME=', "hostname",
        ';DATABASE=', "db_name", ';PORT=', "port", ';COMMITONEOF=0;'),
    encoding = "latin1"
)

However, I am not sure if this is helpful as the code generally works with the old version of R. When I run odbc::odbcListDrivers() I get the exact same list of drivers as before. So, I assume the issue is not related to the current driver. The 'IBM DB2 ODBC DRIVER' (Version 11.5) is installed and the connection via ODBC using other tools works perfectly.

In case, it may be relevant. I have Rtools 4.3 installed, but had some issues earlier with Rtools. image

Interestingly, the connection via JDBC works well. So, it think, it must be an issue with ODBC.

Any ideas?

lorenzbr avatar Aug 22 '23 13:08 lorenzbr