Connect Sql server in Ruby on rails - ruby-on-rails

I need to connect to a SQL Server database, I installed gem 'tiny_tds' gem 'activerecord-sqlserver-adapter' gem 'deprecated'
my yml file:
default: &default
adapter: sqlserver
host: basddatos.dyndns.org
username: zu
password: pass
pool: 5
timeout: 5000
development:
<<: *default
database: Basdatos_2016
GEMFILE
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
#SQl Server
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'
gem 'ruby-odbc'
gem 'deprecated'
gem 'dbd-odbc'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
I get this error: TinyTds::Error Server name not found in configuration files
WHY? thanks

This isn't a full answer but a debugging suggestion (I needed the example space). Try setting the development block in your database.yml to:
development:
adapter: sqlserver
host: basddatos.dyndns.org
username: zu
password: pass
pool: 5
timeout: 5000
database: Basdatos_2016
Do you still get the same error?

Related

Rails Test failed could not connect to server: No such file or directory (PG::ConnectionBad)

i'm trying to run tests on my ruby on rails application but when i type rails test, it return this error:
/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
it seems that it require the gem pg, or a PostgresSQL database, but i'd like to run it in sqlite3 database,so i check my Gemfile and database.yml
database.yml
default: &default
adapter: postgresql
encoding: unicode
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
#database: db/development.sqlite3
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
<<: *default
database: db/production.sqlite3
GemFile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.2'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'sqlite3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
gem 'sqlite3'
end
group :production do
gem "pg"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise','~>4.7.1'
i've tried to run rails db:migrate and rails db:create the two sqlite database are present in the db direcotry, is there other things that i've miss?
thank's

PG::ConnectionBad: could not connect to server (heroku)

i can push to heroku just fine.. however when I run a rake i get this error:
PG::ConnectionBad: could not connect to server
I can run locally ok so not really sure why I am having trouble pushing to heroku - any help would be great
I suspect this is related to my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# 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:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
Also here is my gemfile:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
group :development do
gem 'sqlite3'
gem 'capistrano'
end
group :production do
gem 'pg'
gem 'mysql2'
gem 'activerecord-mysql-adapter'
gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'coffee-rails'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'sass-rails', '>= 3.2'
gem 'autoprefixer-rails'
gem 'will_paginate', '~> 3.0.7'
gem 'will_paginate-bootstrap'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
You should not commit database.yml into heroku:
When Rails applications are deployed to Heroku a database.yml file is
automatically generated for your application that configures
ActiveRecord to use a PostgreSQL connection and to connect to the
database located at DATABASE_URL. This behavior is only needed up to
Rails 4.1. Any later version contains direct support for specifying a
connection URL and configuration in the database.yml so we do not have
to overwrite it.
Read heroku documentation about this.

rake db:schema:dump NoMethodError: undefined method `info_schema_query'

I'm trying to connect to an SQL Server 2012 database from a Ruby on Rails application. I get this error when running the rake command. Am I supposed to run the command bundle install every time I install a new gem? I'm not sure why I'm getting the error below NoMethodError: undefined...
rake db:schema:dump RAILS_ENV=development
rake aborted!
NoMethodError: undefined method `info_schema_query' for #<ActiveRecord::ConnectionAdapters::SQLServerAdapter:0x007fba899762b0>
Tasks: TOP => db:schema:dump
This is my database.yml file
default: &default
adapter: sqlserver
encoding: utf8
port: 1433
pool: 5
username: myuser
password: secretpassword
socket: /tmp/mysql.sock
host: 184.168.194.51
development:
<<: *default
database: mydbname
test:
<<: *default
database: mydbname
production:
<<: *default
database: simple_cms_production
username: simple_cms
password: <%= ENV['SIMPLE_CMS_DATABASE_PASSWORD'] %>
This is in my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'tiny_tds', '~> 0.6.2'
gem 'sql_server', '~> 0.1.1'
gem 'activerecord-sqlserver-adapter', '~> 4.1.0'
gem 'activerecord-sqlserver-adapter-schemas', '~> 1.0.2'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]

ActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: when using postgres

I am trying to deploy my first rails application on digital ocean in Ubuntu, I am unsure if I am doing this right. I initially had my production database in postgres and test and production in sqllite. In frustration, I changed all my databases to postgres my changing the database.yml. I am unsure if I did that correctly But I had this error: ActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: . When I was in sqllite. I was not sure if I had to tell the server to switch to production mode or if it was configured to use sqllite.
What I want to do is use postgres instead of sqllite. I am using nginx and Unicorn. MY database is blank so I dont need to transfer anything. I have made the postgres database within postgres, I just need to point my app to that database. (I am unaware if I need to do something else
I have used this database.yml
development:
adapter: postgresql
encoding: unicode
host: localhost
database: blog_development
pool: 5
username: bob
password: password
test:
adapter: postgresql
encoding: unicode
database: blog_test
host: localhost
pool: 5
username: bob
password: password
production:
adapter: postgresql
encoding: unicode
host: localhost
database: blog_production
pool: 5
username: bob
password: password
Gem file:
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'bootstrap-sass' # for using bootstrap-rails"
gem 'faker'
gem 'will_paginate'
gem 'annotate', '~> 2.6.5'
gem 'font-awesome-rails' # for using font-awesome icons
gem 'redcarpet', '~> 2.1.1'
gem 'coderay', '~> 1.1.0' # For nice code snippets
gem 'devise'
gem 'sidekiq'
gem 'haml-rails'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'guard-rspec'
end
group :test do
gem 'capybara'
gem 'factory_girl_rails', '4.2.0'
end
gem 'pg', '0.15.1'
group :development, :test do
gem 'rspec-rails'
# Use sqlite3 as the database for Active Record in testing
end
group :production do
gem 'rails_12factor', '0.0.2'
end
I have the rest of the code on my github: https://github.com/RubyQuarry/Bootstrap_blog
Run rake db:drop db:create db:drop to drop your old database(s) and recreate the new ones in Postgres.

Can't start rails server - sqlite3 adapter error

I'm trying to teach myself ruby on rails and I'm trying to create a simple application to start with. I'm following the tutorial at http://guides.rubyonrails.org/getting_started.html#creating-a-new-rails-project but am having difficulty starting the server. When I try start up the server and go to the localhost,
Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in
config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or
'sqlite3' add the necessary adapter gem to the Gemfile.
I'm tried to look up a solution/reason why this happens on other questions but to no avail.
My Gemfile looks like this
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:
https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
I'm using
Ruby 2.1.3
and when I type
gem list
I find I'm running
rails 4.1.6
sqlite3 (1.3.9 x86-mingw32)
Can anyone point me in the right direction?
Make sure your config/database.yml has an appropriate database driver set for current environment:
development:
adapter: sqlite3 # check if you have sqlite3 here
encoding: ...
database: ...
pool: ...
username: ...
password: ...
Also don't forget to set it for all other environments you want to use sqlite3 in.
I've never used sqlite but from the error I'm guessing you have a line in database.yml that says:
adapter: sqlite3_adapter
that should instead be:
adapter: sqlite3
Edit: ninja'd
You can put your sqlite3 gem to development in Gemfile
group :development do
gem 'sqlite3'
//*Your other gem to only development
end
wrong adapter in your database.yml file.
use this:
adapter: sqlite3

Resources