I am looking to implement a way to test the database connection for our application.
We are currently having connectivity issues and therefore want to be able to check connectivity without having to login.
Is there a way to display a page stating database connection is up or database connection is down dependent upon whether connection fails. If any additional information is needed please let me know.
Only beginning to learn the ropes so apologies if I'm short on detail.
You can check if the connection is possible by running the following script:
require './config/environment.rb' # Assuming the script is located in the root of the rails app
begin
ActiveRecord::Base.establish_connection # Establishes connection
ActiveRecord::Base.connection # Calls connection object
puts "CONNECTED!" if ActiveRecord::Base.connected?
puts "NOT CONNECTED!" unless ActiveRecord::Base.connected?
rescue
puts "NOT CONNECTED!"
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With