From: Peter Bailey Date: 2007-06-01T03:45:58+09:00 Subject: Re: Help with Ruby < - > Oracle Connectivity Brian Candler wrote: > On Wed, May 30, 2007 at 11:12:02PM +0900, Peter Bailey wrote: >> I know that I'm able to use and >> connect with my database using SQLPlus, which came with the client. My >> "tnsnames.ora" file shows this: >> ... >> (ADDRESS = (PROTOCOL = TCP)(HOST = graphicsdb-prod.bna.com)(PORT = >> 1521)) >> ... > > Unfortunately, you've missed out the important bit, which is what goes > where > the first "..." is. That's the service name, and that's the name you use > to > refer to the host when connecting to it. > >> I'm using DBI here, but, I'm ignorant. I don't know whether I need to >> use it or not. It's all I've found in googling around to do this. > > The homepage for ruby-oci8 is at > http://ruby-oci8.rubyforge.org/ > > You can use this directly - it's a simple enough API. Using the DBI > layer > around this means that in theory you can write code which talks to > databases > other than Oracle. But that's only true if you don't use any > Oracle-specific > SQL. > > If you want an OO abstraction layer, look at ActiveRecord. > >> But, anyway, nothing you suggest is working for me. > > "Nothing is working" is not helpful. Unless you show exactly what you > tried, > and exactly what error(s) you got - cut and paste - then I'm not going > to be > able to help you. > > Showing a working sqlplus command line would also be extremely helpful. > Basically, the same parameters you give there should be usable in your > oci8 > connect string. > > Brian. OK, Brian. Thanks for your help. Well, here's the dinky script I'm trying to use. This script was borrowed, in fact, from the oci8 site. require 'oci8' require 'dbi' begin # connect to the Oracle server dbh = DBI.connect("DBI:OCI8:ORCL:graphicsdb- prod.bna.com/grpprod.bna.com", "user", "passw") # get server version string and display it row = dbh.select_one("SELECT VERSION()") 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 And, I get this: An error occurred Error code: 12154 Error message: ORA-12154: TNS:could not resolve the connect identifier specified Program exited with code 0 And, here's what I've tried with SQLPlus. It's not doing the same thing as above, but it's interrogating the same database. First, I simply connected to the database using the SQLPlus initial GUI. Then, SQL> SELECT file_size from GRAPHIC.RENDITION where image_name = 'zc1' and format_name = 'pdf'; FILE_SIZE ---------- 62116 -- Posted via http://www.ruby-forum.com/.