Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Using Remote Data Access with SQL Server CE 2.0
Subject:   Why INSERTing records in SqlServerCe database taking much time?
Date:   2005-02-16 00:37:22
From:   Arif.
Hi,


If I insert about 150 records (insides a loop) into SqlServerCe database, it takes approximately 57 seconds. But when I insert about 2000 records(insides a loop) it takes approximately 55 minutes to more than an hour. The code snippet is as follows:


System.IO.FileInfo info = new System.IO.FileInfo( appPath + "\\products.txt");


System.IO.StreamReader reader = info.OpenText();


while( (tokenstr = reader.ReadLine())!=null )


{


tokens = tokenstr.Split(',');


cmd.CommandText = "insert into products (bar_code,description,price) " +


"values ('"+tokens[0] + "','" + tokens[1] + "'," + tokens[2] +")";


try


{


cmd.ExecuteNonQuery();


}


catch(SqlCeException sqlceE)


{


MessageBox.Show("SqlCeException: " + sqlceE.Message);


}


}// end while loop



If 150 records takes 60 seconds then 2000 records must take:


150 / 2000 records = 60 / x seconds


=> x = (60 * 2000) / 150


=> x = 800 seconds = 800 / 60 minutes = 13.333 minutes


So 2000 records insertion must take 14 to 20 minutes, but it is taking 55 minutes to more than an hour. This is a huge time.


Please help me to reduce this insertion time. Also what may be the cause of this delay.


Arif.