database.yml
Configuring database.yml for IBM DB2
In order to connect a Rails application to any database, you need to specify the adapter that you intend to use and the credentials in the config\database.yml file. Let’s see how to do this for IBM DB2.
Prerequisites
You will need to have the IBM DB2 driver and adapter installed on your system (if you don’t, run gem install ibm_db or install them through the Starter Toolkit for DB2 on Rails).
Two types of connection
There are two type of connections available to suite your needs: through an Alias or through TCP/IP address. Typically the Alias based connection is used to connect to a local database, while the net address one is used for remote databases.
Alias based connection
development:
adapter: ibm_db
database: demo
username: db2admin
password: db2password
schema: cangiano
Database represents the database alias DEMO. All the fields above are mandatory except for schema. If you don’t specify any schema, the adapter will use the username by default (you’re highly encouraged to specify the schema, in order to prevent issues due to the schema_info table being shared among applications).
TCP/IP connection
development:
adapter: ibm_db
database: demo
username: db2admin
password: db2password
schema: cangiano
host: myhostname
port: 50000
‘host’ can be an hostname or an IP address.
Notes
Linux/Unix users will need to set the environment with the command:
. /home/db2inst1/sqllib/db2profile
Please note that you need to specify ‘ibm_db’ and not ‘db2′ in order to use the IBM adapter.
If you have any questions, please join us at the Rubyforge forum.
Posted by Admin | October 15 2007 11:00 pm
on Rails
Marco on 17 Mar 2008 at 12:16 pm #
I’ve some troubles using schema parameter, i’ve got:
[IBM][CLI Driver][DB2] SQL0567N “MYSCHEMA” non รจ un ID di autorizzazione valido. SQLSTATE=42503
SQLCODE=-567
I’ve installed DB2 connect 8.2 with fixpack 16, if i use find_by_sql and i specify the schema ONLY inside the query it works but doing so i lose all rails advantages