Welcome Guest | Login

Connecting to Remote DB from development env.

Hi i am pretty much a novice to rails and i wanted to connect to a Legacy DB lying on a different server.Actually trying to migrate my application to Ruby on rails .When i supply credentials in database.yml as below

adapter: mysql
database: PandaLogDB
username: xxxx-xxxxx
password: xxxxxxxxx
host:xxxxxxx.xxxxx.xxx

it still does not connect to the remote DB and keeps looking into the Local DB which i have deployed some sample data
for intial development purposes.Are there any other specific configuration changes i need to make to tell the application
to look into a remote DB or does it require some more additional data like the Port and stuff in the database.yml file .I still want the DB to lie on that server and connect to it from both my development and production instances.could you guys please help me out here .Thanks
-P


2007-04-18 11:47 AM

Hello Railskid,

I think you should be able to connect to the remote database from the server. Are you able to do it from the shell ?

You should probably contact the helpdesk for this sort of issue.

2007-04-18 12:50 PM

HostingRails Support
This is the way I have connected to remote databases. You need to create an entry in your database.yml file and create a model for the database in app/models

The sample database.yml file would look like this:

production:
# all your database config info

# create a name for the connection, anything that makes sense to you is fine; don't forget to add in the proper information
pandalog:
 adapter: ###
 database: ###
 username: ###
 password: ###
 host: ###.##.###
Then using pandalog as the name, create a pandalog.rb model in your app/models directory containing the following info:
class Pandalog < ActiveRecord::Base
 self.abstract_class = true
 establish_connection :pandalog
end
That should work for you.

2007-04-18 06:37 PM

Thanks willc,It some how worked without needing to create a model :-) i am not sure how though.BTW does creating a model explictly and establishign the connection slow the application down? do you have any idea about this?
Thanks
railskid

2007-04-18 10:24 PM

No, creating a model won't slow an application down.

2007-04-19 02:02 AM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!