15

I have created a database named database.db

When I create a table in the database I get the error:Error: file is not a database

nehal@nehal-Inspiron-5559:~/Desktop/UAV$ sqlite3 database.db 
SQLite version 3.20.1 2017-08-24 16:21:36
Enter ".help" for usage hints.
sqlite> CREATE TABLE users(
   ...> password varchar(10),
   ...> email text,
   ...> name text
   ...> );
Error: file is not a database

How do I resolve the error?

user7441
  • 397
  • 2
  • 5
  • 11

4 Answers4

8

Create database without the .db extension.
for e.g. sqlite3 users //this creates a database names users

user7441
  • 397
  • 2
  • 5
  • 11
4

The error can occur when a database was created with cipher.
So sqlite3_open succeded but any sqlite3_exec or sqlite3_prepare will be failed with this error.

Aikon Mogwai
  • 4,954
  • 2
  • 18
  • 31
  • 1
    can you elaborate on this a bit more? I am working with cipher and get I this. – Async- Dec 08 '21 at 08:31
  • 1
    After `sqlite_open` you should provide cipher params. How to do it is depended on your cipher library. I use [SQLite3 Multiple Ciphers](https://utelle.github.io/SQLite3MultipleCiphers/) and this library has both `C` and `SQL-pragma` APIs. So I run several sql statement via `sqlie3_exec` like `pragma =` and then work with database as usual. – Aikon Mogwai Dec 08 '21 at 10:33
0

You can also use

.open users

it will also create the database

and to open an existing database users.db use

.open users.db

if .db is not used new database of same name will be created

Devanshu
  • 883
  • 10
  • 22
0

Same problem with WPF and SQLiteAdministrator creating a SQLite v3 DB with Database->New->SQLite 3 DB option and "Data Source=whatever.s3db; Version=3" in the WPF code using System.Data.SQLite library.

Select Database->Migrate to SQLite3 option in SQLiteAdministrator solves the problem. Its works for me. I hope this helps someone.