1

リソースが制限されたデバイス Unitech PA690 で Windows Mobile 6.5 用のアプリケーションを構築していますが、SQL サーバーのコンパクト エディション データベースにレコードを挿入するときに速度の問題が発生しています...コンパクト データベースに値を挿入するための最良かつ最速の方法を知っている人はいますか? これが私の挿入テストコードです。私は直接挿入を使用しています:

private void button1_Click(object sender, EventArgs e)
    {
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        string conn = "Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\AppDatabase1.sdf;Persist Security Info=False";
        SqlCeConnection connection = new SqlCeConnection(conn);
        connection.Open();
        int z = 0;
        string name = "stack";
        string surname = "overflow";
        progressBar1.Maximum = 2000;
        while (z<2000)
            {
                try
                {
                    SqlCeCommand cmd = new SqlCeCommand("Insert into test (id,name,surname) values (@id, @name, @surname)", connection);
                    cmd.Parameters.AddWithValue("@id", z);
                    cmd.Parameters.AddWithValue("@name", name);
                    cmd.Parameters.AddWithValue("@surname", surname);
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.ExecuteNonQuery();
                    z++;
                    progressBar1.Value = z;

                }
                catch (SqlCeException)
                {
                    MessageBox.Show("!!!","exception");
                }
                finally
                {

                }
            }
        stopwatch.Stop();
        MessageBox.Show("Time: {0}" + stopwatch.Elapsed);
        connection.Close();

    }

経過時間は 96 秒で、挿入速度は 21 行/秒になります。ここで挿入速度を改善するための最良の方法を知っている人はいますか? このモバイル デバイスの方が遅いことはわかっていますが、次のリンクによると、挿入速度は少なくとも 400 行/秒である必要があると思います: SQL CE slow insert、それとも間違っていますか? 非常に頻繁に挿入される約 20,000 行のファイルがあるので、助けてください... ありがとう、

4

1 に答える 1