How can I perfom VACUUM command using Entity Framework Code-First approach?
Is the following syntax correct:
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreCommand("VACUUM");
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreCommand("VACUUM");
In fact that is NOT working :(.
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreCommand("VACUUM");
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.Connection.Open();
Code: Select all
using (SQLiteConnection conn = new SQLiteConnection(mySQLiteConnectionStringBuilder.ToString()))
using (SQLiteCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "VACUUM";
conn.Open();
var rowsAffected = cmd.ExecuteNonQuery();
conn.Close();
}
Your download link says "The owner either removed the files or restricted access, or there's a typo in the link.". Could you please reupload a test project to Dropbox?bairog wrote: ↑Wed 24 Oct 2018 07:23[/b]2) For some reason rowsAffected equals 0 even if I use two cmd.ExecuteNonQuery() one after another - first one slightly shrinks database from 47.3 mb to 45.7 mb, second one leaves it's size unchanged). Shouldn't it be real number of affected rows?
I use dotConnect for SQLite 5.11.1202 and EF6.
I've uploaded sample databases here
1. Please executebairog wrote: ↑Wed 24 Oct 2018 07:23raises "SQLite error cannot VACUUM from within a transaction" exception. Of course there is no any transaction opened. And it doesn't matter whether I open coonection before or not:Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreCommand("VACUUM");
Why that is not working?Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.Connection.Open();
Code: Select all
var conn = (((IObjectContextAdapter)myDbContext).ObjectContext.Connection as System.Data.Entity.Core.EntityClient.EntityConnection).StoreConnection;
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "VACUUM";
cmd.ExecuteNonQuery();
Code: Select all
(((IObjectContextAdapter)myDbContext).ObjectContext.Connection as System.Data.Entity.Core.EntityClient.EntityConnection).StoreConnection.Open();
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreCommand("VACUUM");
2. The number of rows affected by the command is returned only for UPDATE, INSERT, and DELETE statements. For more information, navigate to https://docs.microsoft.com/en-us/dotnet ... tenonquery.bairog wrote: ↑Wed 24 Oct 2018 07:23[...]Code: Select all
using (SQLiteConnection conn = new SQLiteConnection(mySQLiteConnectionStringBuilder.ToString())) using (SQLiteCommand cmd = conn.CreateCommand()) { cmd.CommandText = "VACUUM"; conn.Open(); var rowsAffected = cmd.ExecuteNonQuery(); conn.Close(); }
For some reason rowsAffected equals 0 even if I use two cmd.ExecuteNonQuery() one after another - first one slightly shrinks database from 47.3 mb to 45.7 mb, second one leaves it's size unchanged). Shouldn't it be real number of affected rows?