Unable to connect to database using RSQLite

so I am trying to access my DB file without success, here is my script:

library(DBI)

library(sqldf)

drv <- dbDriver("SQLite")

con <- dbConnect(drv, dbname = "database.sqlite")

      

and here is the error:

drv <-dbDriver ("SQLite")

con <-dbConnect (drv, dbname = "database.sqlite")

Error in rsqlite_connect (dbname, loadable.extensions, flags, vfs): Failed to connect to database: unable to open database file

I checked, of course, and made sure I installed the packages correctly and set my working directory.

+3


source to share


2 answers


I solved my problem and its a little awkward:

I saved the file to my desktop. since my OS is installed in my native language (Hebrew), the file path contained one Hebrew word in it, and while this does not create a problem reading tables in R, it does create a problem for the SQL join.



it was easy to solve - I saved the file in a new folder on my hard drive (c: \ database), set as the working directory and everything was fine.

+2


source


I can duplicate this error in two ways:

  • The file exists, but you do not have permission to open it.

This could be due to operating system permissions. Check your rights.

  • The file does not exist and you do not have permission to create it.


If SQLite is prompted to open a database file that does not exist, it tries to create one. If this fails, you will receive this error message. This will fail if the path to the database file (in this case, the current working directory) does not allow creating files. Check your rights.

Note that if the file exists but is corrupted, I get a different error:

> con <- dbConnect(drv, dbname = "database.sqlite")
Error in rsqlite_send_query(conn@ptr, statement) : 
  file is encrypted or is not a database
> 

      

so that probably is n't your problem.

+3


source







All Articles