Closing a DB connection using rails

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

how can i over come this situation

am i missing some thing in this