You can test the Ruby on Rails database connectivity with
the db2dsdriver.cfg file to ensure that the db2dsdriver.cfg file
is valid and the Ruby driver is installed correctly.
Before you begin
You must ensure that the IBM® data server client or IBM Data
Server Driver Package software is installed, and the db2dsdriver.cfg file
is created in your environment with a required data source name (DSN)
entry. You can use the contents of the db2dsdriver.cfg.sample file
to create the db2dsdriver.cfg file.
You
must have a working Ruby on Rails environment. You can install Rails
and its dependencies by issuing the following command:
$ gem install rails --include-dependencies
Note: The gem
install command requires an internet connection.
You
must install the Ruby driver before testing the connection. You can
install the Ruby driver by issuing the
gem install ibm_db-x.x.x.gem command.
The 32-bit Ruby driver gem file is located in the
<DB2_Install_Path>/ruby/ruby32 path.
The 64-bit Ruby driver gem file is located in the
<DB2_Install_Path>/ruby/ruby64 path.
For detailed steps to set up the Ruby on Rails environment, see
Getting started with IBM data servers on Rails
Procedure
To test the Ruby on Rails connectivity with the db2dsdriver.cfg file:
- Change path to the <DB2_Install_Path>/bin path.
The <DB2_Install_Path> is the install path of
the IBM data server client or IBM Data
Server Driver Package software.
- Issue the ruby validate_install.rb <dsn_name> <username> <password> command.
The <dsn_name> is the DSN in the db2dsdriver.cfg file
that you are testing the connection to. The <username> is
the valid user ID that is used to connect to the target data source.
The <password> is the valid password that is
associated with the specified user ID.
- Optional: You can also test the Ruby connection
without the db2dsdriver.cfg file with the ruby
validate_install.rb <database_name> <host_name> <port> <username> <password> command.
The <database_name> is the database name that
you are testing the connection to. The <host_name> is
the host name of the server where the target database resides. The <port> is
the database listener port that is configured on the database server.
The <username> is the valid user ID that is
used to connect to the target data source. The <password> is
the valid password that is associated with the specified user ID.
Results
The
ruby validate_install.rb <dsn_name> command
output displays the connection test status for the Ruby driver.
If
you receive the following error message, you have a 32-bit Ruby environment
but you configured the 64-bit IBM data
server driver:
wrong ELF class: ELFCLASS32: lib/ibm_db.so (LoadError)
To
configure the 32-bit IBM data
server driver:
- Run or source the 32-bit profile script file:
- In the 32-bit Bash or Korn shell environment, run the db2profile32 file.
- In the 32-bit C shell environment, source the db2cshrc32 file.
- Issue the gem install <DB2_Install_Path>/ruby/ruby32/ibm_db-x.x.x.gem command.
Example
The following command output shows a successful connection
to the
sampledsn DSN entry:
$ ruby validate_install.rb sampledsn username password
Connection to database sampledsn is successful.
$ ruby validate_install.rb sample samplehost.domain.com 50000 username password
Connection to database sample is successful.