# Closing a DB connection using rails

**URL:** <https://www.ruby-forum.com/t/closing-a-db-connection-using-rails/120073>\
**Category:** Rails\
**Created:** [November 13, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/closing-a-db-connection-using-rails/120073 "2007-11-13T15:42:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [November 13, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/closing-a-db-connection-using-rails/120073/1 "2007-11-13T15:42:43Z")

</div>

Hello All,

I am working now on Admin Console project where the admin user should  
be export tables in a schema to CSV format.

I am able to do this perfectly with the current database

but when i am selecting a table from a different database (i.e is  
which is not used by rails i.e is test or production or some xyz  
Database ) its throwing me an error

even i tried with this one and i am able to export,

@conn1=ActiveRecord::Base.establish\_connection(:adapter =\> “mysql”,  
:host =\> “localhost”,  
:username =\> “root”,  
:password =\> “xxxx”,  
:database =\> schemaname  
)

i tried ActiveRecord::Base.remove\_connection

but after a scuessfull completion of exporting its getting lost the  
current data base connection and the presnent state of the Logged in  
User

how can i over come this situation

am i missing some thing in this

Thanks  
Jagan
