Setting up a DB2 database using Ruby on Rails

I am trying to establish a connection to a DB2 database and my rails application using the ibm_db gem. However, most of the available documentation is a) very old and b) too technical for me to understand. After installing the gem, I updated my development database with the structure shown here , but when I try to start the Rails database I get the error:

Could not connect to [XXXXXX] due to: uncaught throw: "Connection error: [IBM] [CLI driver] SQL1531N Connect failed because the name specified in the DSN connection string key string was not found in either db2dsdriver. Cfg or db2cli.ini configuration file Data source name specified in connection string: "XXXXXXXX \". SQLCODE = -1531 "(RuntimeError)

I know this means I need to create a db2dsdriver.cfg file, but I don't know where to start, how to create it, or where to save it. The docs say that I should simulate it after the .sample file that comes with the gem, but I'm not sure what information goes there. You can see an example file below:

<configuration>
   <dsncollection>
      <dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"/>
      <!-- Long aliases are supported -->
      <dsn alias="longaliasname2" name="name2" host="server2.net1.com" port="55551">
         <parameter name="Authentication" value="SERVER_ENCRYPT"/>
      </dsn>
   </dsncollection>
   <databases>
      <database name="name1" host="server1.net1.com" port="50001">
         <parameter name="CurrentSchema" value="OWNER1"/>
         <wlb>
            <parameter name="enableWLB" value="true"/>
            <parameter name="maxTransports" value="50"/>
         </wlb>
         <acr>
            <parameter name="enableACR" value="true"/>
         </acr>
         <specialregisters>
            <parameter name="CURRENT DEGREE" value="'ANY'"/>
         </specialregisters>
         <sessionglobalvariables>
            <parameter name="global_var1" value="abc"/>
         </sessionglobalvariables>
      </database>
      <!-- Local IPC connection -->
      <database name="name3" host="localhost" port="0">
         <parameter name="IPCInstance" value="DB2"/>
         <parameter name="CommProtocol" value="IPC"/>
      </database>
   </databases>
   <parameters>
      <parameter name="GlobalParam" value="Value"/>
      <!-- Client configuration for Optim Performance Manager Extended Insight (OPM EI) and Optim Configuration Manager (OCM)-->
      <!-- <parameter name="connectionSupervisorLibrary" value="/home/pureQuery/pqcmx"/> -->
      <!-- <parameter name="connectionSupervisorProperties" value="controllerURL=server1.net1.com:65000,httpControllerURL=http://ibmdatacmserver:12206,cmxUUID=myuuid"/> -->
   </parameters>
</configuration>

      

+3


source to share


1 answer


I know this is an old post, but it got pressured today.

Could you please tell us what you have specified in your database.yml file.

You do not need to worry about the presence of the database and related information specified in the dsdriver.cfg file. You can directly specify in database.yml and it will be brought up.

Your database.yml file should look like this (if you are on Rails 4)

default: &default
  adapter: ibm_db
  username: praveen
  password: *******
  #schema: db2inst1
  #host: localhost
  #port: 50000
  #account: my_account
  #app_user: my_app_user
  #application: my_application
  #workstation: my_workstation
  #security: SSL
  #timeout: 10
  #authentication: SERVER
  #parameterized: false

development:
  <<: *default
  database: railsdb

      



You will need to provide the database details, port, host, username and password for the corresponding keys. If you don't know how the sections in database.yml should actually look like, just create a rails app with the following command

rails new myapp -d ibm_db

The -d option generates a database.yml skeleton specific to ibm_db

thank

Praveen

0


source







All Articles