SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

How To Fix ActiveRecord::ConnectionTimeoutError with Sinatra

       

If you get this error message

ActiveRecord::ConnectionTimeoutError could not obtain a database connection within 5.000 seconds (waited 5.001 seconds)

Try closing the connection after each request using "after" in Sintara.

# app.rb

after { ActiveRecord::Base.connection.close }

get '/' do
    erb :index
end

The after block will get called after each request and close your database connection.

Tagged w/ #sinatra #ruby #databases #activerecord #errors

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app