0

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.

Community
  • 1
  • 1
Jerod Johnson
  • 764
  • 7
  • 15
  • trying moving this import: `_ "github.com/alexbrainman/odbc"` after the standard one: `"database/sql"` – Yandry Pozo Nov 07 '17 at 18:20
  • I tried swapping the imports, no luck. Thanks @YandryPozo – Jerod Johnson Nov 07 '17 at 20:13
  • 1
    It looks to me more like an issue with unixODBC and/or CData driver. Check your DSN with isql. Try to actually connect and query some data. Once unixODBC and below are sorted out, the go side should generally work without issues. I would also suspect that cryptic error message is ascii interpreted as utf-16 or something like that. – Seva Nov 08 '17 at 10:03
  • 1
    If isql works, but go code still doesn't. You can also try checking what odbc libraries your go binary is linked against and compare it to isql. – Seva Nov 08 '17 at 10:30
  • isql definitely works. I'll look into the linked libraries. Thanks, @Seva – Jerod Johnson Nov 08 '17 at 13:05
  • @Seva, I've compared the linked libraries and they are the same, any other thoughts? – Jerod Johnson Nov 08 '17 at 15:59

1 Answers1

1

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.

Jerod Johnson
  • 764
  • 7
  • 15