Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:25:11+00:00 2026-06-03T17:25:11+00:00

So I know how that this works like this ActiveRecord::Base.connection_pool.with_connection do |conn| conn.execute(sql) end

  • 0

So I know how that this works like this

ActiveRecord::Base.connection_pool.with_connection do |conn|
   conn.execute(sql)
end

but I’m trying to use the connection with actual Activerecord models, so something like

conn.Url.first

is there a way to do something like that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:25:12+00:00Added an answer on June 3, 2026 at 5:25 pm

    Found out this isn’t possible, but within the with_connection block any ActiveRecord calls should use the connection that is checked out from the Rails connection pool

    so in this example

    ActiveRecord::Base.connection_pool.with_connection do |conn|
        Url.first
    end
    

    It should check out a connection from the pool set aside for Rails in your database.yml :pool setting, let your active record call use it and then check it back in

    However, this only works in rails 3+ … you can see the code change that makes this possible here

    Rails 2.3 (old way) http://apidock.com/rails/v2.3.8/ActiveRecord/ConnectionAdapters/ConnectionPool/with_connection

    Rails 3 http://apidock.com/rails/v3.0.0/ActiveRecord/ConnectionAdapters/ConnectionPool/with_connection

    This guy explains the patch in this blog post
    http://coderrr.wordpress.com/2009/05/05/activerecords-with_connection-is-now-useful/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this kind of issue is most discussed. But I would like
I know that this has already been asked here but the answer (using a
I know that this feature will be deprecated in C++0x, but for me as
I know that this may be an amateur question but for some reason I
I know that this can be easily done by using if(i%5 == 0 OR
I know that this question is asked a lot, I checked all of the
I know that this is jumping the gun slightly as it is early days
I know that this question is very similar to the question posted here .
I know that this question has been asked several times and I've read all
I know that this is a repeated question. I have found very similar questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.