douyi0219 2017-11-07 15:03
浏览 428
已采纳

无法在Linux上使用alexbrainman / odbc连接到Go中的第三方ODBC驱动程序

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.

  • 写回答

1条回答 默认 最新

  • doupeng8419 2017-11-08 19:38
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)