[R] odbcConnect won't open a DSN that opens using isql (Linux: Ubuntu)

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Sun Nov 1 21:10:20 CET 2026


On Mon, 26 Oct 2026 18:06:05 +0000
Chris Evans via R-help <r-help using r-project.org> wrote:

> > connEOS <- odbcConnect("EOS")  
> Warning messages:
> 1: In grepl("PWD=", cs) :
>    unable to translate '<c0><d3>6<ed><b1>{' to a wide string
> 2: In grepl("PWD=", cs) : input string 1 is invalid

This is quite weird.

The 'cs' string is the connection string returned by the C code inside
RODBC:

   stat <- .Call(C_RODBCDriverConnect, as.character(connection), id,
                 as.integer(believeNRows), as.logical(readOnlyOptimize))
   # ...
   cs <- attr(stat, "connection.string")
   if(grepl("PWD=", cs)) {
       # mask the password inside the returned object

RODBC passes the connection string back to R like this:

 #define buf1_len 8096
 // ...
 SQLCHAR buf1[buf1_len];
 // ...
 retval = SQLDriverConnect(
  thisHandle->hDbc, NULL,
  (SQLCHAR *)Rf_translateChar(STRING_ELT(connection, 0)),
  SQL_NTS,
  (SQLCHAR *)buf1, (SQLSMALLINT)buf1_len,
  &tmp1,
  SQL_DRIVER_NOPROMPT
 );
 if(retval == SQL_SUCCESS || retval == SQL_SUCCESS_WITH_INFO) {
  // ...
  PROTECT(constr = Rf_allocVector(STRSXP, 1));
  SET_STRING_ELT(constr, 0, Rf_mkChar((char *)buf1));
  // ...
  Rf_setAttrib(ans, Rf_install("connection.string"), constr);

Somehow, the 'buf1' string isn't filled at all and R receives
uninitialised stack contents instead of the effective connection
string, despite the return value indicates a successful connection. And
yet 'idbc' works using the same connection string, suggesting that the
problem isn't inside the MDBtools driver.

How did you install the RODBC package? If there's nothing obviously
wrong with your R package installation, further investigation will
probably require stepping through the C code in a debugger.

-- 
Best regards,
Ivan



More information about the R-help mailing list