Tuesday, October 31, 2006

Ruby on Rails with Oracle Express

My company uses Oracle.  I'm the only guy that uses Rails, building my prototypes first "the right way" and then whipping something up in .Net once I have the idea what I want.  Recently I put Oracle Express (10g) onto my machine, which works with our regular environment, but I needed it to work with Rails as well.

I had a little difficulty.  If I just set the database to "XE", the default, which carries with it in the tnsnames.ora file enough information to figure out what machine it is running on, I would get an error ORA-12560: TNS protocol adapter error.

However, if I added "host: localhost" explicitly, the error would change to ORA-12514: TNS listener does not currently know of service requested in connect descriptor.

It's worth noting that I can connect Ruby/Rails to the regular Oracle instance from this machine, so I know that whatever issue I'm having, it's an Express-specific one.

Turns out to be something I would not have expected.  Instead of specifying database and assuming that host will be calculable from it, specify the host in a way that you also specify what database you want.  Try   "host: localhost/xe".  Leave the database line out.  Works for me!


Technorati tags: , , ,


Bryan Evans said...

Hi Duane

Just wanted to let you know that I came across your blog by doing a Google search for Rails and Oracle Express, and your post was very helpful.

Thanks and keep up the good work.

Duane said...

Thanks Bryan, glad it helped. I've always tried to follow a simple rule -- if I need an answer to something, and googling doesn't help me, then solve it and post it for the next guy to find :).

Chris said...

Thanks! Another not, if you add your domain to the end of your host usually, you should remove it. You will get a TNS error without doing so.

Chris said...
This comment has been removed by a blog administrator.