Connect oracle from nodejs

后端 未结 4 1791
既然无缘
既然无缘 2021-01-14 00:11

Last few weeks I had been trying to connect oracle db from my nodejs code. What I found so far are 2 main libraries such as https://github.com/mariano/node-db-oracle which i

相关标签:
4条回答
  • 2021-01-14 00:46

    From what I understand, Set PATH puts the string you specified at the beginning of your Path environment variable. I entered the instant client folder path at the beginning.

    C:\oraclexe\app\oracle\instantclient_12_1;

    It fixed the oracle binding error, but the queries wouldn't work. Then, I added the vc11 folder path BEFORE the instant client path, so it looks like this :

    C:\oraclexe\app\oracle\instantclient_12_1\vc11;C:\oraclexe\app\oracle\instantclient_12_1;

    Now my queries work!

    0 讨论(0)
  • 2021-01-14 00:47

    Did you get the Instant Client as described here? If I'm reading this correctly, you need the Basic (or Basic Lite) and SDK Instant Client packages. The SDK package might have the header file you're having trouble with.

    Side note: in my experience, you don't always need to add Instant Client to PATH; you can usually get away with just making sure your executable can find it (which often means just dropping it in the same directory).

    0 讨论(0)
  • 2021-01-14 00:47

    Set the oracle client path in the command prompt like below before starting the Node application

    Set PATH=C:\oraclexe\app\oracle\instantclient_12_1;%PATH%

    I had the above problem , this resolved mine and I am now able to connect to oracle .

    But the one problem I am still facing is executing the select statement .It always returns error. I am able to execute SP, create statements and everything else without error . I am stuck here and sort of disappointed .

    0 讨论(0)
  • 2021-01-14 01:00

    I know this is an old post... just wanted to mention a sure way for nodejs to communicate to oracle without extra modules.

    Set up oracle so it can create and receive http requests. There are a few ways to do this:

    The easiest is to turn on the epg gateway:

    • http://www.oracle-base.com/articles/10g/dbms_epg_10gR2.php

    Also you can setup modplsq:

    • http://www.comp.dit.ie/btierney/oracle11gdoc/appdev.111/b28424/adfns_web.htm

    or the Apex listener:

    • http://www.oracle.com/technetwork/developer-tools/apex-listener/overview/index.html?ssSourceSiteId=otnpt

    Then in node js do a standard http.get:

    http.get("http://localhost/accessor/myschema.my_procedure?x=1&y=2", function(res) {
        console.log("Got response: " + res.statusCode);
    }).on('error', function(e) {
       console.log("Got error: " + e.message);
    

    });

    Whichever approach...secure oracle so that it will only respond to the ip address of the nodejs server. So if running on localhost:

    if owa_util.get_cgi_env('REMOTE_ADDR') = '127.0.0.1' then 
       --ok
    else
       -- fail
    end if;
    

    Also block calls to every other package and procedure. There are few ways to do this depending on the path you take.

    Make sure you do this at a minimum:

    • create a white list of items which can be called from the web
    • require that all urls contain the schema name such as: myuser.myprocedure
    • make sure the first portion of the url (up to the query path) contains a-z 0-9 only
    • really a good white list will take care of most of these items

    There you have it...no need to worry if a module will break or stop working with the next release.

    AND...you can easily communicate from Oracle to Node use:

    • apex_web_service.make_rest_request
    • utl_http
    0 讨论(0)
提交回复
热议问题