I tried to use DBI gem to connect my PostgreSQL server - ruby

I tried to use DBI gem to connect my PostgreSQL server.
Here is my code:
DBI.connect('DBI:Pg:DBNAME:IP', 'ROLE', 'PWD')
Here is an error message I got:
NameError: uninitialized constant DBI::DBD::Pg::Database::PGError
Did you mean? TypeError
I have no problem when I use dbi to connect Mysql server.
dbn = DBI.connect('DBI:Mysql:DBNAME:IP', 'USERNAME', 'PWD')
I also update my all gems:
pg, dbi and dbd-pg.

Don't use unmaintained gem dbi, you can see the readme says no longer maintained. Instead use the ruby pg gem


Issue regarding the connection between ruby and oracle database using sequel gem

I am using sequel gem to connect and access my oracle database using a ruby program.
I have installed sequel gem and oracle instant client both. I have also installed ruby-oci8 gem. But still getting this error as follows:-
Loaderror: cannot load such file -- oci8 (Sequel::AdapterNotFound)
My code is :-
require 'sequel'
DB = Sequel.connect('oracle://localhost/XE', :user=>'SYSTEM', :password=>'tiger')
DB['select NAME from EMPLOYEE'].each do |row|
puts row
Please help me to fix this. I don't even know that what would be the right form of this line
Sequel.connect('oracle://localhost/XE', :user=>'SYSTEM', :password=>'tiger')
My database name is XE, user is SYSTEM and password is tiger.
The LoadError indicates you don't have the oci8 gem installed. You can probably fix it using: gem install oci8

gems/anemone-0.7.2/lib/anemone/storage.rb:28:in `MongoDB': uninitialized constant Mongo::Connection (NameError)

Using Anemone, I get this error when trying to use MongoDB:
gems/anemone-0.7.2/lib/anemone/storage.rb:28:in `MongoDB': uninitialized constant Mongo::Connection (NameError)
The code looks like this:
require 'anemone'
require 'mongo'
Anemone.crawl("my.site") do |anemone|
anemone.storage = Anemone::Storage.MongoDB
# more code here...
Any suggestions?
The Mongo storage driver in Anemone hasn't been updated since 2010 and still uses the syntax for the 1.x version of the Mongo ruby driver.
The easiest way to work around the problem is to instruct your script to use the older gem.
First, check if you have a 1.x version of the gem on your system. From the command line:
gem list mongo
It should give you something like:
*** LOCAL GEMS ***
mongo (2.2.5, 1.12.5)
mongodb (2.1.0)
I had a 1.x version (1.12.5), so I'm good to go. If you don't, you can install one using:
gem install mongo -v 1.12.5
Then, instruct your script to use the 1.x version of the gem by placing this line at the top of your file:
gem 'mongo', '=1.12.5'
Note, if you're using Mongo anywhere else in your script, it will now need to use the 1.x syntax.
Also, you may get a warning asking you to install bson_ext, which you can do with:
gem install bson_ext

rubyrep Exception caught: PG::ConnectionBad: connection is closed: show search_path

I am trying to use rubyrep to just scan between two databases and am getting the following error:
Exception caught: PG::ConnectionBad: connection is closed: show search_path
rubyrep gem is 1.2.0
pg gem is 0.17.1
ruby 2.1.5
I have verified that from the command line (psql) I can connect and select from the databases. Any ideas?
Here is what I have found out in order to make rubyrep work:
The stock gem that comes with gem install rubyrep does not seem to work when in combnation with the latest pg gem. I have not tried using older versions of pg, because:
Using this fork of rubyrep seems to work. You need to clone it with git and then run a gem build rubyrep.gemspec in order to build the gem locally. Then, you run gem install ./rubyrep-XXXXXX.gem and you are done.
I tried the above gem with both ruby 2.1.5 and jruby. It was equally painfully slow.

Connect to MSSQL database with Ruby

Hi I'm trying to connect to MS SQL database via DBI gem.
I've installed dbi and dbd-odbc gems.
I've set up ODBC driver (System DSN) as 'MYDSN'
While executing the command:
require 'dbi'
mydb = DBI.connect('dbi:ODBC:MYDSN', 'user', 'password')
I'm getting this error:
DBI::InterfaceError: Unable to load driver 'ODBC' (underlying error: uninitialized constant DBI::DBD::ODBC)
What is the issue?
Thank you.
I resolved this issue by installing gem ruby-odbc
gem install ruby-odbc
Somehow it worked, connection established and now I can work with database.

Sequel: DB2 Adapter Not Found

Okay, I've been trying to connect to a DB2 Database. I've been trying to use Sequel, in the hope of building some POROs for accessing data in my DB2 Database.
So after installing Sequel, I've been trying to do the following in irb
require 'sequel'
DB = Sequel.connect('db2://myuser:mypass#myhost.com:10000/mydatabase')
Which gives me the following error:
Sequel::AdapterNotFound: LoadError: cannot load such file -- db2/db2cli
Looking at the sequel source for the DB2 Adapter inside sequel, this is generating from this require statement
require 'db2/db2cli'
So I installed every gem I thought It could be trying to require: db2, ibm_db and dbi. I've also downloaded the CLI and put it in my system path and downloaded an DB2 Express C. No matter what I try, I can't get past this require statment.
You probably want to install ibm_db and use ibmdb://... instead of db2://.... db2://... is for the old db2/db2cli driver which is not available in gem form (you can get it at http://rubyforge.org/frs/download.php/8264/ruby-db2-0.4.4.tar.gz).