OperationalError: (sqlite3.OperationalError) unable to open database file

1.6k Views Asked by At

first I know that there are some questions like this and I read them but they were not useful for me.

I have some .csv files from financial markets and I want to transfer them to a SQLite3 database table. I used Odo a Python package for this purpose but I faced a big error.

This is sample data:

EUR/USD,20170102 00:00:01.265,1.0523,1.05307
EUR/USD,20170102 00:00:05.818,1.0523,1.05307
EUR/USD,20170102 00:00:06.833,1.05158,1.05349

Let 's go step by step: all csv files and DB are in D drive. I created sina DB, and then Sina1 table with this command(in SQLite Studio):

CREATE TABLE sina.sina1 (Symbol text, DateTime text, Bid real, Ask real);

Then I tried to input the data by this code with Python(Anaconda):

[There are 2 csv files. both of them are same but first one with header and second one without header as did in Odo documentation.]

import sqlite3
from odo import odo, discover, resource 

# connect to sina database
conn = sqlite3.connect('d:/sina.db')

# use odo to detect the shape and datatype of csv file
data_shape = discover(resource('d:/with_header.csv'))

# Transfer from csv file to table called 'sina1' within database 'sina.db'
odo('d:/parsclick/without_header.csv', 'sqlite:////d:/sina.db::sina1', dshape = data_shape)

# close database
conn.close()

I tested this code line by line in different ways. I created a new table in this DB(with SQLite studio) and get data with select command in python interpreter, so it does not have connection problem.I manually entered data_shape with this format(same as table):

 data_shape = "var * {simbole: string, DateTime: string, Bid: float64, Ask: float64}"

which is a few different from :

var * {simbole: ?string, DateTime: ?datetime, Bid: float64, Ask: float64}

obtained from first code.

I also changed permission of all files in D drive to full access for everybody and ran computer(windows 10) as admin.Furthermore I checked paths. But these did not change the story and every time caused this error:

File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\default.py", line 410, in connect return self.dbapi.connect(*cargs, **cparams)

OperationalError: (sqlite3.OperationalError) unable to open database file (Background on this error at: http://sqlalche.me/e/e3q8)

0

There are 0 best solutions below