【问题标题】:How to connect Informix server using Node js with ODBC connectivity?如何使用带有 ODBC 连接的 Node js 连接 Informix 服务器?
【发布时间】:2018-12-06 10:54:06
【问题描述】:
  1. 我有 Linux Enterprise Server 10 SP2(x86_64) - 内核 2.6.16.60-0.21-smp。
  2. 我在上面的 linux 服务器上安装了 IBM Informix Dynamic Server Version 11.10.FC1。
  3. 我有 Windows 2008 服务器,带有 odbc(dns 名称,例如:eadmin)(IBM INFORMIX 3.80 32 位),用于安装 informix 驱动程序和 XAMPP v3.2.2
  4. 我有开发 PC 作为 windows 7 和 odbc(例如 eadmin 的 dns 名称)(IBM INFORMIX 3.80 32 位),用于安装 informix 驱动程序并安装 wamp 2.4 作为开发服务器。

我的网站在服务器和我的开发电脑 (Windows 7) 中运行良好。

现在我想迁移到 Node Js,我想要

  1. 在我的开发机器中要遵循哪些步骤?

  2. 我试过了 npm 安装 odbc, npm 安装 ibm_db, npm install win32ole 等

  3. 全部出错。 (或者不知道怎么安装,需要python报错什么的)

  4. 我想使用 ODBC dns 连接 Informix 服务器,因为我在 PHP 中无缝连接。

  5. 简单的 mongoDB、mysql 等连接工作正常,但 informix 不行。

【问题讨论】:

    标签: node.js windows odbc informix


    【解决方案1】:

    首先您应该升级您的 Informix 产品。 IDS 11.10 太旧了。 ODBC 3.80 甚至更早(3.80 包含在 2002 年发布的 CSDK 2.70 中)。

    新的 Informix 服务器(例如 12.10.xC11)提供使用 MongoDB 驱动程序直接连接的选项。 看:

    https://www.ibm.com/developerworks/community/blogs/da95bfce-e0cf-4056-8bc3-2deea450e378/entry/Informix_and_NoSQL_JSON_Wire_Listener_Setup_and_Mongo_Shell?lang=en

    使用 JSON 侦听器,无需通过 ODBC 驱动程序连接到 IDS 服务器。 Uou 可以使用连接到 MongoDB 的相同 NodeJS 模块。

    不过,如果您无法升级引擎,有几个 Informix NodeJS 开源驱动程序,但它们都需要更新版本的 Informix ODBC 驱动程序和 ESQL/C 库。

    https://github.com/OpenInformix/IfxNode/blob/master/LocalBuildWindows.md https://www.npmjs.com/package/informix

    最新的 ODBC 驱动程序是 4.10.xC11。

    Wankdander 的“node-odbc”模块可以在 Windows 上运行:

    https://github.com/wankdanker/node-odbc

    我使用 CSDK 4.10.FC8 中的 Informix ODBC 驱动程序对其进行了测试,因为它使用 ODBC 标准调用,它甚至可以与 3.80 之前的版本一起使用。

    -------- 编辑 -------

    刚刚从头开始测试。 您将需要:

    1. NodeJS(我用的是最新的稳定版 8.11.3)
    2. C 编译器(我使用 Visual Studio 2015,我想“免费”Express 版本就足够了)
    3. Python

    步骤如下:

    使用编译器环境集启动会话:

    C:\Program Files (x86)\Microsoft Visual Studio 14.0>d:
    
    D:\Infx>cd infx\nodejs811
    
    D:\Infx\nodejs811>dir
     Volume in drive D is Data750
     Volume Serial Number is F0B7-2E44
    
     Directory of D:\Infx\nodejs811
    
    21/06/2018  12:26    <DIR>          .
    21/06/2018  12:26    <DIR>          ..
    12/06/2018  22:43        22,778,520 node.exe
    11/02/2018  01:08               702 nodevars.bat
    11/02/2018  01:08             8,985 node_etw_provider.man
    21/06/2018  12:26    <DIR>          node_modules
    11/02/2018  00:08             4,974 node_perfctr_provider.man
    11/02/2018  01:08               867 npm
    11/02/2018  00:08               483 npm.cmd
    12/06/2018  01:50               867 npx
    12/06/2018  01:50               483 npx.cmd
                   8 File(s)     22,795,881 bytes
                   3 Dir(s)  201,607,630,848 bytes free
    D:\Infx\nodejs811>
    

    设置nodeJS环境:

    D:\Infx\nodejs811>nodevars.bat
    Your environment has been set up for using Node.js 8.11.3 (x64) and npm.
    C:\Users\Administrator> 
    

    安装node-gyp(构建odbc模块所需)

    C:\Users\Administrator>npm install node-gyp
    npm WARN Administrator No description
    npm WARN Administrator No repository field.
    npm WARN Administrator No README data
    npm WARN Administrator No license field.
    
    + node-gyp@3.7.0
    added 1 package in 1.821s
    
    C:\Users\Administrator>
    

    安装odbc模块:

    C:\Users\Administrator>npm install odbc
    
    > odbc@1.4.1 install C:\Users\Administrator\node_modules\odbc
    > node-gyp configure build
    
    
    C:\Users\Administrator\node_modules\odbc>if not defined npm_config_node_gyp (node "D:\Infx\nodejs811\node_modules\npm\no
    de_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" configure build )  else (node "D:\In
    fx\nodejs811\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" configure build )
    Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
      odbc.cpp
      odbc_connection.cpp
      odbc_statement.cpp
      odbc_result.cpp
        ....
        ....
      dynodbc.cpp
      win_delay_load_hook.cc
      strptime.c
         Creating library C:\Users\Administrator\node_modules\odbc\build\Release\odbc_bindings.lib and object C:\Users\Admi
      nistrator\node_modules\odbc\build\Release\odbc_bindings.exp
      Generating code
      Finished generating code
      odbc_bindings.vcxproj -> C:\Users\Administrator\node_modules\odbc\build\Release\\odbc_bindings.node
      odbc_bindings.vcxproj -> C:\Users\Administrator\node_modules\odbc\build\Release\odbc_bindings.pdb (Full PDB)
    npm WARN Administrator No description
    npm WARN Administrator No repository field.
    npm WARN Administrator No README data
    npm WARN Administrator No license field.
    
    + odbc@1.4.1
    added 3 packages in 31.827s
    
    C:\Users\Administrator> 
    

    检查它是否适用于连接到 Informix ODBC DSN 的简单 js 脚本:

    C:\Users\Administrator>type test.js
    var db = require('odbc')()
      , cn = "DSN=ids1210;UID=informix;PWD=dummypwd;";
    
    db.open(cn, function (err) {
      if (err) return console.log(err);
    
      db.query('select * from systables where tabid = 1', [42], function (err, data) {
        if (err) console.log(err);
    
        console.log(data);
    
        db.close(function () {
          console.log('done');
        });
      });
    });
    
    C:\Users\Administrator>node test.js
    [ { tabname: 'systables',
        owner: 'informix                        ',
        partnum: 1049238,
        tabid: 1,
        rowsize: 500,
        ncols: 26,
        nindexes: 2,
        nrows: 177,
        created: '2017-10-18',
        version: 65831,
        tabtype: 'T',
        locklevel: 'R',
        npused: 7,
        fextsize: 32,
        nextsize: 32,
        flags: 0,
        site: null,
        dbname: null,
        type_xid: 0,
        am_id: 0,
        pagesize: 4096,
        ustlowts: 2018-06-17T00:11:37.000Z,
        secpolicyid: 0,
        protgranularity: ' ',
        statchange: null,
        statlevel: ' ' } ]
    done
    
    C:\Users\Administrator>
    

    我没有 ODBC 3.80,我用 4.10 测试它,但理论上它应该可以工作,无论驱动程序的版本。 没有 64 位版本的 ODBC 3.8,所以您需要使用 32 位版本的 NodeJS 并在 32 位模式下编译。

    【讨论】:

    • 谢谢 J_S。我不是服务器管理员。我无权升级它。您能否解释一下在开发 PC 中要遵循的步骤,如何使用 ODBC 完成连接?
    • 我试过 node odbc !但是在安装过程中它给出了python错误。还有什么办法吗?
    • 我需要先安装 python 2.7 并尝试安装 npm install odbc 吗?
    • 是的,您的机器中需要一些 Python 版本,因为它被 odbc 模块构建脚本使用
    • 查看编辑后的答案,我添加了构建模块的确切步骤。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2013-06-10
    • 1970-01-01
    相关资源
    最近更新 更多