When I try to seed my application I get the error:
No connection could be made because the - target machine actively refused it. - connect(2)
I believe the reason why is because I was having issues with mysql2 so I uninstalled it along with the MySQL 5.5 Servers and then switched to sqlite3. I think the server for mysql2 is running in the background so this could be the issue. How would I fix this? How would I turn off the Mysql2 local host server or whichever server it is that's causing this issue?
I am running on Windows 7 64-bit.
Rails 3.0.9
SQLite3 1.3.4
Thanks.
Note: I can migrate and drop fine.
Edit:
config/database.yml
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
UPDATE:
I tried restarting the PC and also remade my application from scratch, still get the error. Disabled Windows Firewall/Comodo Firewall and tried again, still failure. I did a System Restore but this did not work either.
Here's the full rake db:seed: https://gist.github.com/1375566
SOLVED:
I have another application I ran rake db:seed in and it worked correctly, so as the accepted answer by clyfe pointed out, Sunspot was the issue. I put together again my application and stopped at adding sunspot and suddenly I got the error:
rake db:seed
(in C:/testagain)
Deleting database now...
rake aborted!
undefined method `searchable' for #<Class:0x52cdca0>
Which means the rake was reading my code inside of my UserPrice model that dealt with Sunspot:
class UserPrice < ActiveRecord::Base
# Sunspot and Websolr configuration.
#searchable do
# text :product_name do
# product.name
# end
# end
end
I commented this out and was able to seed correctly. Then I went on to try sunspot using these commands in the following order:
rails g sunspot_rails:install
rake sunspot:solr:start (also un-comment model)
rake sunspot:reindex
rails server
rake db:seed
Everything works as it should.
You are using Sunspot for indexing and search as I see from your gist https://gist.github.com/1375566
Make sure that the Solr server is started before you seed.
What happens is that:
when the model saves
it tries to send data to the Solr server for indexing
but it cannot connect
Possible issues:
the Solr server is not started
the Sunspot Solr connection is not configured corectly in /config/sunspot.yml
the port it's blocked by a firewall
If you haven't started a Solr server instance already, you can start the Sunspot-bundled Solr server with the following rake command:
rake sunspot:solr:start
I dont think it is because of mysql, I think it is a firewall issue on the port that you are trying to access. You can test by stopping the service or using the mysql workbench to stop the server on that machine. I doubt that will resolve the issue, since the firewall may be interfering.
Comment out the skip-networking in my.cnf in your MySQL configuration.
Related
I'm currently trying to setup a Redmine installation for our team. I can't seem to establish a connection to our MSSQL server from within rails.
$ RAILS_ENV=production bundle exec rake db:migrate
rake aborted!
TinyTds::Error: closed connection
/home/admin/.rbenv/versions/2.6.6/bin/bundle:23:in `load'
/home/admin/.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I installed sqlcmd to test the connection outside out rails, and I managed to login and create and drop a table as a test. I suspect it's my database.yml. I have to connect to an MS SQL Instance, and the server in running on a different port. Tried to tweak around with the settings a bit, but couldn't get it working.
database.yml
production:
adapter: sqlserver
database: Redmine01
dataserver: server\instance
port: ####
username: user
password: "password"
encoding: utf8mb4
While I've played around with rails a bit before, my rails knowledge is definitely limited and I've never set up a connection to an MS SQL server or used the TinyTds gem, therefore I suspect that I simply didn't configure my environment correctly. Hence my post here. I'd really appreciate if one of you rails experts could take a look at the database config. The information I could find regarding configuring rails to connect to named instance combined with a non-standard SQL port were limited.
As a sidenote, for sqlcmd I used "-S server\instance,####" to establish the connection. Which I've surely tried in the database.yml too, but without any success.
In case anyone stumbles upon this, leaving out the instance does the job.
production:
adapter: sqlserver
database: Redmine01
dataserver: server
port: ####
username: user
password: "password"
I'm trying to use rails 4.2.6 to develop an app. I'm trying to use postgres for database. Server starts fine but when I try loading a page it throws this "No connection pool for ActiveRecord::Base" error.
What could it be?
EDIT
The pg gem wasn't working properly. I had to comment it before starting the server and then uncomment it from my GemFile afterwards. I realized that I was using Ruby 2.3 instead of Ruby 2.0 (as intended). I removed ruby 2.3 and set up everything under ruby 2.0 environment. It's now working properly.
I had read somewhere that there were some issues with the 'pg' gem in newer Rails releases, requiring people to use 'gem install pg --pre' instead for installing the gem. I tried that, but then my app was requiring the 'pg' gem in my GemFile and, well, the problem stated above showed up again.
This is how my database.yml file ended up:
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: -------
password: -------
pool: 5
development:
<<: *default
database: myDbName
If you are experiencing this error from a rake task, chances are you are not running the :environment task before your task.
Changing:
task :task_name do
end
to:
task task_name: :environment do
end
Should fix the issue.
This issue arises when the server cannot find the corresponding database it depends on to pull data from.
I had same issue from my end, I updated my version of Sqlite3, and it was higher than the version that the current Puma Server version supports.
I simply had to uninstall the Sqlite3 version, and then install the version supported by the current version of Puma Server.
gem uninstall sqlite3
This will uninstall the updated version of Sqlite3, and then you run the code below stating the version supported by your current server.
gem install sqlite3
Or you can as well open your Gemfile, and then include the version for the database that you are using
gem 'sqlite3', '~> 1.3.6'
N/B: The sqlite3 version is the most current version as at the time of writing this answer
And then run
bundle update
to install the version of the database that you specified.
That's all.
I hope this helps.
For PostgreSQL your database.yml file should look something like that:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: your_db_name
Also make sure that you have the gem installed: in your Gemfile:
gem 'pg'
Finally, restart your server.
Hope that helps
Edit: I almost forgot, make sure you have your PostgresSQL running, check this link for download and setup.
Check the database.yml if all settings are ok. If its the first time and you didn't create the database yet use this command to create the database
rake db:create
If the database already exists try reset the db migrations,
rake db:migrate:reset
Hope it'll solve the problem. Go to rails console and try something to check if its working or not.
I had to simply restart the server for the warning to go away.
I've encountered the same problem when I try to access the Model before creating the DataBase.
Make sure you run rake db:migrate at least once.
If you already run migration then check the Database as mentioned in previous answers.
In my case, the config/database.yml was taking variables from the environment:
# ...
test:
<<: *default
database: <%= ENV.fetch("DB_NAME") %>_test
username: <%= ENV.fetch("DB_USER") %>
password: <%= ENV.fetch("DB_PASS") %>
# ...
The error was coming when the new terminal window where I was running the bundle exec rails spec did not have those variables initialized.
Doing,
$ export DB_NAME=mydb
$ export DB_USER=myuser
$ export DB_PASS=mypass
$ bundle exec rails spec
fixed the issue.
I had to restart the server, and make sure you entered username and password. Create development and test databases
when you are running rails db:migrate in data base rows will be created according to your migration files. you can see schema for further info.
Rails 5
New app
Using Postgresql for both test and development
Specs run, so Rails can connect to Postgresql
But when I started the web app, I got "No connection pool with id primary found."
Ran 'bin/rails db:migrate:reset' and restarted the app. It worked. No idea why.
database.yml:
development:
adapter: postgresql
encoding: unicode
database: rails5_development
pool: 5
username: foo
password: bar
host: localhost
port: 5432
test:
adapter: postgresql
encoding: unicode
database: rails5_test
pool: 5
username: foo
password: bar
host: localhost
port: 5432
When I try to create a rails app on DigitalOcean (Ubuntu/Nginx/passenger) it always defaults to sqlite3 and I get an error message in the browser:
SQLite3::CantOpenException
But when I use WebBrick locally it works fine running on PostGres. What could be causing this and how can I get my app to use PostGres? It's installed on DigitalOcean and I can migrate and seed the database in my app, it just seems to want to use sqlite3. Any ideas?
The database configuration is in config/database.yml:
adapter: sqlite3
should be:
adapter: postgresql
Without seeing your database.yml I'd guess you have development setup with postgres but not production.
Trying to deploy my rails app to Heroku for the first time, I ran into many problems. The app crashed, and you can look at the logs in the image: http://i.stack.imgur.com/bsx1b.png
Even worse, when I tried to look at my application locally, it failed to work on postgreSQL environment.It worked fine when I went back to use sqLite3 in database.yml. I thought the problem might be that I actually have to install postgreSQL, in addition to adding pg gem and running bundle install.
I went ahead to install PostgreSQL with the one-click installer (Windows 7 64bit). After reboot, a simple rails server or bundle install commands started failing, so I reinstalled the entire ruby & rails.
Now rails server command works fine, and it prompts a different error when I try to look at my app on local environment. So right now I have pgAdmin III and Rails
PG::Error
fe_sendauth: no password supplied
I tried to follow this, but I couldn't find "pg_hba.conf." I guess the answer was based on a different OS.
And now again, the bundler is not working, giving me errors...
Questions:
1) Was I right to install postgreSQL with the one-click installer? Because this caused my ROR to "crash" somehow, and I had to reinstall rails altogether. 2) I think I am going to delete everything related to postgreSQL, reinstall Rails, and start everything from beginning. What are the steps that I have to take? All the references I've looked at do not seem to fit Windows environment.
In my gemfile, I have
gem 'pg'
gem 'thin'
In my database, I have
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: utf8
database: mangfeel_development
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: utf8
database: mangfeel_test
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: utf8
database: mangfeel_production
pool: 5
timeout: 5000
Errors I'm getting at this moment, after installing PostgreSQL:
c:\ruby\myapp>rails server
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:926:in `report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:244:in `activate_dep'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:236:in `activate'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:1307:in `gem'
from C:/RailsInstaller/Ruby1.9.3/bin/rails:18:in `<main>'
When I run bundle install:
Gem::InstallError: The 'json' native gem requires installed build tools
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing json (1.7.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.5'` succeeds before bundling.
So I will just remove pgAdminIII, PostgreSQL, Ruby on Rails entirely, and start from scratch.
I thought deploying wasn't going to be this hard, but moving from SQLite3 to PostgreSQL is taking more time and effort than I thought it would. I would really appreciate some help on this problem.
------------------------------------------------------------------------------------------------------------------------
UPDATE: AFTER REINSTALLING EVERYTHING, I'M DOING THE SETUP AGAIN FROM SCRATCH.
I checked that my SQLite3 version app worked fine. So I moved onto setting up postgreSQL. I got the following error when I first set up my postgreSQL. By setting up, I mean editing config/database.yml and installing the gem 'pg' and removing the gem 'sqlite3.' When I tried to connect to localhost:3000, I got the following error:
ActiveRecord::ConnectionNotEstablished
After some research, I found that there could be more steps to setting the db. So I ran the bundle command,
bundle exec rake db:setup
But then in the console, I got the following error when I ran bundle exec rake db:setup.
Couldn't create database for {"adapter"=>"postgresql", "host"=>"localhost", "encoding"=>"utf8", "database"=>"db/myapp_test", "pool"=>5, "timeout"=>5000}
rake aborted!
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
c:/ruby/myapp/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:load => environment
When I tried to connect to localhost:3000, I got the above error again, instead of ActiveRecord::ConnectionNotEstablished.
Question: What did I do wrong, and how do I solve the problem?
If you have error:
PG::Error
fe_sendauth: no password supplied
You have good news, your app can work with PostgreSQL database now. (But you need to configure some thing)
After installing PostgreSQL, you can create new rails app using PostgreSQL by command:
rails new my_app -d postgresql
This is database.yml will be created:
development:
adapter: postgresql
encoding: unicode
database: my_app_development
pool: 5
username: my_app
password:
test:
adapter: postgresql
encoding: unicode
database: my_app_test
pool: 5
username: my_app
password:
production:
adapter: postgresql
encoding: unicode
database: my_app_production
pool: 5
username: my_app
password:
You see that, three database has username and password field, this is account user in Postgresql, three database in database.yaml file will created by this user. So you need to provide username and password for it. Default after install Postgresql, it created a user with username is postgresql and password is postgresql. You can use it.
If you want to use other user, just open pgAdmin III and create new user by right click on Login Roles and choose New login role to create new user with password. Then put that username and password to database.yaml file.
After that, all you need now, is find and open pg_hba.conf file to make some configure for app can work with PostgreSQL. I'm not using Windows for a long time, so I'm not sure where it is, but you can find in folder you installed PostgreSQL. Example, if you install on E:\ partition, maybe you can find it in:
E:\PostgreSQL\version\data
After you found it, open and find a line:
# "local" is for Unix domain socket connections only
local all all ident sameuser
Change it to:
# "local" is for Unix domain socket connections only
local all all md5
Then restart your Postgresql database. To create database for app, run rake db:create or rake db:create:all. Now your app can using PostgreSQL database now, so happy :).
I am not an expert on Rails, but here is one of my YAML files for a recent deployment i did on heroku with POSTGRES
development:
adapter: postgresql
host: localhost
database: dbname_development
production:
adapter: postgresql
host: localhost
database: dbname_production
Seems like you are missing a parameter called host in case of postgres deployment
Steps to Move From SQLite3 to PostgreSQL on Windows, for an Existing Rails App to Deploy To Heroku:
In your Gemfile, find gem 'sqlite3' and change it to gem 'pg'. Run bundle install.
Download Postgres from here. Choose the one-click installer and select your OS environment (32 or 64 bit). During installation, do NOT choose to install any extra software it recommends you to install. It will possibly mess up your existing Rails and you will have to reinstall Rails.
Now go to config/database.yml, and change it to the following format. The current one is set for SQLite3 and is missing some fields necessary for PostgreSQL.
development:
adapter: postgresql
encoding: unicode
database: my_app_development
pool: 5
username: my_app
password:
test:
adapter: postgresql
encoding: unicode
database: my_app_test
pool: 5
username: my_app
password:
production:
adapter: postgresql
encoding: unicode
database: my_app_production
pool: 5
username: my_app
password:
The adapter is different, and there are fields for username and password. The default username and password is postgresql, but if it doesn't work (it didn't work for me), then go to your pgAdmin, create a new login role to make another username/password (check the option to make it a super user) and use that.
4, At this point, you can create a new app by running
rails new my_app -d postgresql
Run your local server, and try connecting to localhost:3000 to see if the welcome page is showing.
5, If everything is working fine, then all you need to do is create a new PostgreSQL database, and migrate your existing models to it. Run
rake db:create:all
rake db:migrate
Done! Now check if your existing app is working fine locally, and try deploying your app to Heroku.
I've had some trouble getting my Rails app to connect to PostgreSQL so I decided to just say screw it and use SQLite for now. (I'm using the tutorial here: http://guides.rubyonrails.org/getting_started.html)
I started a BRAND NEW, fresh Rails app from this tutorial. When I visit my app in the browser after deleting public/index.html, I get this the first time:
Please install the pg adapter: `gem install activerecord-pg-adapter` (no such file to load -- active_record/connection_adapters/pg_adapter)
That's odd to me because I'm not mentioning PostgreSQL anywhere. Here's my databases.yml:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
To make things more confusing, I only get that "pg adapter" error on the first load. For every subsequent page request, I get this error:
ActiveRecord::ConnectionNotEstablished
So even though I removed all mention of PostgreSQL, I'm still getting errors. What could be going on?
you didn't mention doing rails server once you created the new web app, did you do this step, or are you still running the old server instance? you will know because the server will fail to start because there is already something running on port 3000. if you didn't shut it down, you need to run the following:
ps aux | grep ruby
find the id of the process and
kill <id>
Okay, it works now for some reason. The only reason I can think of is that I shut down my server last night and restarted it today.