0

I tried accessing my Rails database from other script:

require 'sqlite3'
db = SQLite3::Database.new "~/Documents/PROJECTS/Ruby/Rails/Vulnerable_Informer/db/development.sqlite3"
db.execute 'SELECT * FROM computers' do |row|
  puts "#{row}"
end

But I have an error:

test_db.rb:5:in `initialize': unable to open database file (SQLite3::CantOpenException)
from test_db.rb:5:in `new'
from test_db.rb:5:in `<main>'

If I create a new SQLite3 file all works, but if I try to access an existing Rails database it fails.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sergey
  • 1
  • Try shutting down your server first, then attempt write into its db. – Sergio Tulentsev May 25 '17 at 12:20
  • 3
    I know this is not an answer to your question per se, but I would really recommend you to use postgres or mysql in your development and you will not encounter issues such as this, it will make your life much easier and even happier. – Eyeslandic May 25 '17 at 13:35
  • SQLite is somewhat of a special animal as it's not really designed for multiple users or multiple sessions talking to it. Using PostgreSQL or MySQL will allow that. Using `rails runner` will make it easier to talk to the database in any case as it'll provide the necessary information to the script to talk to the database. https://stackoverflow.com/q/9757261/128421 – the Tin Man May 25 '17 at 20:37

0 Answers0