简体   繁体   中英

Node.js - Error: [unixODBC] on db.open with Docker

I'm using ODBC to access my database (Advantage Database Server) in an Node.js backend service. On my test server (CentOS 7.2.1511) everything works right. But on the production system (Docker, Debian 8.4) a weird error occurs when the app tries to connect to the database.

This is my package.json :

{
  "name": "some-name",
  "version": "47.11",
  "private": false,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.13.2",
    "debug": "~2.2.0",
    "express": "~4.13.1",
    "jade": "~1.11.0",
    "morgan": "~1.6.1",
    "serve-favicon": "~2.3.0",
    "sync-request": "~2.0.1",
    "winston": "2.1.1",
    "express-winston": "0.4.1",
    "cookie-parser": "1.4.0",
    "underscore.string": "3.2.2",
    "string-template": "0.2.1",
    "underscore": "1.8.3",
    "request": "2.67.0",
    "odbc": "1.2.1",
    "node-schedule": "1.1.0"
  }
}

The following code snippet produces the error:

var pool = new (require("odbc").Pool)()
var db = require("odbc")()
var connectionString = "DSN=Advantage;UID=<username>;PWD=<password>"
var con = db.openSync(connectionString)

Error-Message:

Error: [unixODBC]顔ĕ
    at Error (native)
    at Database.openSync (/usr/src/app/node_modules/odbc/lib/odbc.js:150:26)
    at repl:1:10
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)

A Perl script connecting the database and reading data from one of it's tables works perfectly fine on the same machine (respectively Docker container). So this is not a misconfigured odbc.ini or some other problem with the odbc driver.

Has someone ever stumbled into this problem and can help? Thank you!

I e-mailed the developer of the ODBC package and he advised me to disable unicode and rebuild the package.

  1. Disable unicode

  2. run npm rebuild

This solved the issue for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM