Search code examples
ubuntugoodbccdata-drivers

Unable to connect to 3rd party ODBC driver in Go with alexbrainman/odbc on Linux


I'm attempting to connect to a data source with a 3rd party ODBC driver (downloadable here) in Go using the alexbrainman ODBC driver. I've tested the DSN in question using:

isql -v "CData Redis Source"

Everything works as expected there. And I know that I have unixODBC 2.3.1 installed (isql --version).

The Problem

When I try to run the following Go program, I get this error message, spawned from the db.Ping() call (which Google translate seems unable to translate):

SQLDriverConnect: {㄰こ0} [unixODBC]湉慶楬⁤潣湮捥楴湯猠牴湩⁧祳瑮硡愠⁴湩敤⁸ㅛ㩝

My code:

package main

import (
  _ "github.com/alexbrainman/odbc"
  "database/sql"
  "log"
)

func main() {
  db, err := sql.Open("odbc","DSN=CData Redis Source")
  if err != nil {
    log.Fatal(err);
  }
  
  var (
    name string
  )
  
  rows, err := db.Ping()
  if err != nil {
    log.Fatal(err)
  }
}

I see the same error if I do a db.Query() or a db.Prepare().

The Details

  • Ubuntu 16.04.3 LTS
  • unixODBC 2.3.1
  • CData Software ODBC Driver for Redis
  • go1.6.2 linux/amd64
  • github.com/alexbrainman/odbc

The Request

I'd be happy with a translation of the error message to help me debug AND/OR some help in determining why my error message is not in English AND/OR an actual proposed solution to the error message.


Solution

  • It turns out that I needed to ensure that the CData Driver was configured to use UTF-16 encoding, as is required by unixODBC. To do so, I edited the driver's INI file:

    /opt/cdata/cdata-odbc-driver-for-redis/lib/cdata.odbc.redis.ini

    [Driver]
    DriverManagerEncoding = UTF-16
    

    Once this was done the CData driver worked with the alexbrainman/odbc database driver (and other Go-related ODBC database drivers) as expected.