Provider Error

D

Daniel

Hi,
I am Daniel, started to work on a application in Ruby. Im
rebuliding a application to ruby from MSAccess. since Im new to Ruby, I
have worked on a code to connect to PostgreSQL. But Im getting a error
message. Can someone help me out. I tired with someother options for
the database provider. I have pasted the code and the error message.

Code:

require 'dbi'
begin
# connect to the MySQL server
# dbh =
DBI::connect("PostgreSQL;localhost;inventory_dev","postgres","B4ckN3w!!")
#dbh=DBI.connect("driver=pg host=localhost port=5432
dbname=inventory_dev user=PostgreSQL password=vacn2002!")
#dbh = DBI.connect('localhost:postgreSQL:inventory_dev','PostgreSQL',
'vacn2002')
#dbh=DBI.connect(driver="Pg",
database="host=localhost,dbname=inventory_dev")
#obj.login(user="PostgreSQL", pass="B4ckN3w!!")

dbh = DBI.connect("PostgreSQL","inventory_dev", "postgres",
"B4ckN3w!!")

#dbh = DBI.connect("DBI:pg:inventory_dev")

#dbh = DBI.connect("Driver={SQL
Server};Server=Intel266;Database=Inventory_DEV;Uid=sa;Pwd=vacn2002;")


# get server version string and display it
row = dbh.select_one("select * from UserList")
puts row
#puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
ensure
# disconnect from server
dbh.disconnect if dbh
end

Error:
ruby DbConn.rb
c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:359:in `parse_url': Invalid Data
Source Name (DBI::InterfaceError)
from c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:226:in `_get_full_driver'
from c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:213:in `connect'
from DbConn.rb:13
 
C

ChrisH

Daniel said:
Hi, ....
require 'dbi'
begin ....
dbh = DBI.connect("PostgreSQL","inventory_dev", "postgres",
"B4ckN3w!!") ....
c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:359:in `parse_url': Invalid Data
Source Name (DBI::InterfaceError)
from c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:226:in `_get_full_driver'
from c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:213:in `connect'
from DbConn.rb:13

Looking at the DBI docs/examples (http://ruby-dbi.rubyforge.org/) it
appears your connect statement should be :
dbh = DBI.connect("DBI:pg:inventory_dev", "postgres","B4ckN3w!!")

But for DBI to work the Postgress driver needs to be installed. You
can see what drivers are available by executing:
DBI.available_drivers.each {|dd| p dd}



Cheers
 
D

Daniel

Hi Chris,
Thanks for your reply. It worked perfectly. Hope to be
in touch with you.
Bye
Daniel.
 
C

ChrisH

Your welcome

BTW, I would be sure to change those passwords now that they are not
private! 9^)

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top