1

I have a Compact Framework application where I run this code:

SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = conn;

cmd.CommandText = "DELETE FROM Empresa";
cmd.ExecuteNonQuery();

The Empresa table has only 187 records, but that instruction runs for over 4 minutes, which is abnormal.

Is there a way to optimize it? This table only has 2 columns. One of them is the identity. If I try adding WHERE id > 0 to the query, the same happens.

Thanks Jaime

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • What build version of SQL CE 3.5 do you use? – ErikEJ Dec 16 '17 at 15:10
  • How can I know it? I can get version of System.Data.SqlServerCe.dll which is 3.5.5386.0. Is that what you mean? – jstuardo Dec 16 '17 at 15:15
  • I have deployed the applicastion to a handheld device and it took 24 minutes to delete 187 records!!!! it is impossible! – jstuardo Dec 16 '17 at 15:41
  • You should use the latest build: http://erikej.blogspot.dk/2017/01/downloading-sql-server-compact-35-sp2.html – ErikEJ Dec 16 '17 at 17:51
  • DELETE is to be known of being very slow. As we do not have TRUNCATE TABLE, which is much faster, in SqlCE, you may use DROP TABLE and create a new one from scratch. DELETE will be slower for the number of index fields. DELETE will not affect the identity column. Using DROP etc. you will loose the identity values. – josef Dec 17 '17 at 07:09
  • it seems that DROP TABLE is not compatible with SqlCommand. I tried cmd.CommandText = "DROP TABLE Table"; cmd.ExecuteNonQuery(); but an exception is shown – jstuardo Dec 17 '17 at 16:00

0 Answers0