views:

60

answers:

2

In C# how can I empty an existing SQLite database?
Is it possible via the Connection String? or by the SQLite manager?

I don't want to issue a drop all tables statement.

I have this code, the new here represents if does not exists create a new one.

try
{
    connStr = @"Data Source=" + databaseFilePath + ";New=True;Version=3;";
    conn = new SQLiteConnection(connStr);
    cmd = new SQLiteCommand();
    cmd.Connection = conn;
    cmd.CommandType = CommandType.Text;
    cmd.Connection.Open();
}
catch (Exception e)
{
    MessageBox.Show("Caught exception: " + e.Message);
    addError("Caught exception: " + e.Message,true);
    return false;
}
A: 

Since SQLite does not enforce referential integrity, you can iteratively delete all information from each table.

Anton Gogolev
Maybe `Truncate` would be better than delete?
Winston Smith
I don't want to issue a drop all tables statement.
Pentium10
I'm talking about *truncating each* table, not *dropping all* tables.
Winston Smith
That is maybe the same. Correct me if I am wrong. In SQLite there is no `Truncate all tables`. So I have to build query up manually, but it would be easier a query to `delete from sqlite_master ...` that will delete all tables in the database. I am after a lightweight method.
Pentium10
That will work but is very inefficient compared with deleting the file.
finnw
+2  A: 

Delete file, that holds database.

FractalizeR