2009-10-30 4 views
0

J'ai un problème de performance lors de l'insertion de données à sqlce.Je suis la chaîne de lecture et de faire des insertions à Mes tables.In LU_MAM table, j'insère 1000 enregistrements avec 8 secondes.Après les tables Mam je fais quelques insère mais ma plus grande table est CR_MUS.Quand je veux insérer l'enregistrement dans CR_MUS, cela prend trop de temps.CR_MUS a 2000 enregistrements et l'insertion prend 35 secondes. Ce qui peut être raison? J'utilise la même logique dans mes fonctions d'insertion. Avez-vous une idée? J'utilise VS 2008 sp1.Problème très intéressant dans Compact Framework

Dim reader As StringReader 
reader = New StringReader(data) 

cn = New SqlCeConnection(General.ConnString) 
cn.Open() 

If myTransfer.ClearTables(cn, cmd) = True Then 
    progress = 0 
    '------------------------------------------ 
cmd = New SqlServerCe.SqlCeCommand 
Dim rs As SqlCeResultSet 
cmd.Connection = cn 
cmd.CommandType = CommandType.TableDirect 
Dim rec As SqlCeUpdatableRecord 

' name of table 

While reader.Peek > -1 
    If strerr_col = "" Then 

     satir = reader.ReadLine() 
     ayrac = Split(satir, "|") 

     If ayrac(0).ToString() = "LC" Then 
      prgsbar.Maximum = Convert.ToInt32(ayrac(1)) 

     ElseIf ayrac(0).ToString = "PPAR" Then 
      . 
      If ayrac(2).ToString <> General.PMVer Then 
       ShowWaitCursor(False) 
       txtDurum.Text = "Wrong Version" 

       Exit Sub 
      End If 
      If p_POCKET_PARAMETERS = True Then 
       cmd.CommandText = "POCKET_PARAMETERS" 
       txtDurum.Text = "POCKET_PARAMETERS" 
       rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable) 
       rec = rs.CreateRecord() 
       p_POCKET_PARAMETERS = False 
      End If 
      strerr_col = myVERI_AL.POCKET_PARAMETERS_I(ayrac, cmd, rs, rec) 
      prgsbar.Value += 1 

     ElseIf ayrac(0).ToString() = "MAM" Then 
      If p_LU_MAM = True Then 
       txtDurum.Text = "LU_MAM " 
       cmd.CommandText = "LU_MAM" 
       rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable) 
       rec = rs.CreateRecord() 
       p_LU_MAM = False 
      End If 
      strerr_col = myVERI_AL.LU_MAM_I(ayrac, cmd, rs, rec) 
      prgsbar.Value += 1 
        ElseIf ayrac(0).ToString = "KMUS" Then 
      If p_CR_MUS = True Then 
       cmd.CommandText = "CR_MUS" 
       txtDurum.Text = "CR_MUS" 
       rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable) 
       rec = rs.CreateRecord() 
       p_TR_KAMPANYA_MALZEME = False 
      End If 
      strerr_col = myVERI_AL.CR_MUS_I(ayrac, cmd, rs, rec) 
      prgsbar.Value += 1 

end while 

Fonction publique CR_KAMPANYA_MUSTERI_I (ByVal f_Line() As String, ByRef myComm Comme SqlCeCommand, rs ByRef Comme SqlCeResultSet, ByRef rec Comme SqlCeUpdatableRecord) As String

Try 
     rec.SetValue(0, If(f_Line(1) = String.Empty, DirectCast(DBNull.Value, Object), f_Line(1))) 
     rec.SetValue(1, If(f_Line(2) = String.Empty, DirectCast(DBNull.Value, Object), f_Line(2))) 
     rec.SetValue(2, If(f_Line(3) = String.Empty, DirectCast(DBNull.Value, Object), f_Line(3))) 
     rec.SetValue(3, If(f_Line(5) = String.Empty, DirectCast(DBNull.Value, Object), f_Line(5))) 
     rec.SetValue(4, If(f_Line(6) = String.Empty, DirectCast(DBNull.Value, Object), f_Line(6))) 
     rs.Insert(rec) 
    Catch ex As Exception 
     strerr_col = ex.Message 
    End Try 
    Return strerr_col 

End Function 

Répondre

0

ok, je l'ai trouvé problem.I suis mal dans CR_MUS.Je craigne cr_mus à chaque fois parce que je ne fais pas p_CR_MUS = false.And Aussi augmentation de la valeur de la barre de progression diminue les performances beaucoup trop.Ainsi, je n'ai pas de problème.