Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails - how to retrieve connection strings

Are there any ways to retrieve the database connection string where my ruby is connected? what i would like to get is the:

1) Database name where the ruby is connected 2) The username of the SQL Server 3) Password of the SQL Server 4) Server name

I want to store it in session variables.

(I'am using MS SQL Server.)

Please help! thanks!

like image 654
Jett Avatar asked Jun 18 '10 02:06

Jett


People also ask

How do I find my connect string?

Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.

How do I find the database connection string in Visual Studio?

Open Visual Studio.Go to view => Server Explorer. Right click on Data Connections and select Add Connection (or) click on Connect to Database icon. You will get add connection window. Provide Server name.


2 Answers

I would go with ActiveRecord::Base.connection_config which returns hash with options for ActiveRecord 3.

like image 131
skalee Avatar answered Nov 02 '22 19:11

skalee


You can access all of the properties described in your database.yaml like this:

ActiveRecord::Base.configurations["development"] => 
{"encoding"=>"utf8", "username"=>"foo", "adapter"=>"mysql", "database"=>"bar_development", "host"=>"localhost", "password"=> "baz"} 
like image 41
Tanel Suurhans Avatar answered Nov 02 '22 19:11

Tanel Suurhans