Fix ActiveRecord::ConnectionNotEstablished

[SeeRM #8780]
Land #3173, Fix ActiveRecord::ConnectionNotEstablished