Search code examples
javascriptoracle-databasedatabase-connectionconnection-string

Connect to Oracle DB from JavaScript


I am using a proprietary automated testing product that uses a javascript engine to run test scripts.

I am trying to connect to Oracle DB on a server to setup test data/environment. My code uses the following connection string:

var dbDriverString = 'Driver={Microsoft ODBC for Oracle};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=1.1.1.1)(PORT=1521))(CONNECT_DATA=(SID=dbname)));Uid=abc;Pwd=abc;';

var connectionString = dbDriverString;
    
if (Database.DoAttach(connectionString, '') == true)
    Tester.Assert('Connected to database.', true);

I installed Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (x64) client on my Windows VM. I am unable to connect to the database. I keep getting the following error:

[Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle failed on SQL_HANDLE_ENV failed.

I have setup all paths correctly. ORACLE_HOME is set, ORACLE_HOME/bin is also set as environment variable. I have also tried to use other drivers/connection strings.


Solution

  • Major issue was a mismatch between Application arch and Drivers arch. Following was done on a fresh vm from scratch:

    1. Application and driver architecture needs to match, i.e. both 32bit or 64 bit.
    2. Control Panel -> Administrative Tools -> ODBC Sources on Win 7 amd64 will show 64bit available drivers.
    3. To check what 32bit is installed, run -> cmd -> c:\Windows\SysWow64\odbcad32.exe.

    If you end up defining a User/System DSN for Oracle_Ora11gHome1 driver (wtf Oracle), TNS Service Name is yourip:port/sid