# DB connection problem in production

**URL:** <https://www.ruby-forum.com/t/db-connection-problem-in-production/168507>\
**Category:** Rails\
**Created:** [May 21, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/db-connection-problem-in-production/168507 "2009-05-21T17:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arfon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@arfon](https://www.ruby-forum.com/u/arfon)\
**Post date:** [May 21, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/db-connection-problem-in-production/168507/1 "2009-05-21T17:13:10Z")

</div>

I have a separate DB for one model in my application and in development  
mode the connection is working properly, in production however it isn’t.

production:  
adapter: mysql  
host: myhost  
username: root  
password:  
database: production\_db

users\_production:  
adapter: mysql  
host: myhost  
username: root  
password:  
database: other\_db

The model that connects to the other database is called User but the  
table it references in other\_db is smf\_users so my User.rb looks like  
this:

class User \< ActiveRecord::Base  
establish\_connection “users\_#{RAILS\_ENV}”  
set\_table\_name “smf\_users”  
end

In production I’m getting this error:

Mysql::Error: Table ‘production\_db. smf\_users’ doesn’t exist:

Note how it is trying to connect to the wrong database and so isn’t  
finding the correct table. As I say, this works in development mode.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![arfon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@arfon](https://www.ruby-forum.com/u/arfon)\
**Post date:** [May 28, 2009, 5:37am UTC](https://www.ruby-forum.com/t/db-connection-problem-in-production/168507/2 "2009-05-28T05:37:34Z")

</div>

From the AWDWR book: “If you pass a symbol to establish\_connection,  
[…]”. Maybe you need to convert your string to a symbol?

establish\_connection “users\_#{RAILS\_ENV}”.to\_sym

Pepe

On May 21, 11:13 am, Arfon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
