Compact Framework中非常有趣的问题

时间:2009-10-30 12:49:32

标签: .net sql-server-ce

我在将数据插入sqlce时遇到了性能问题。我正在读取字符串并插入My tables。在LU_MAM表中,我插入了1000条记录,时间为8秒。在Mam表之后,我进行了一些插入但是我最大的表是CR_MUS。当我想将记录插入CR_MUS时,需要花费太多时间.CR_MUS有2000条记录,插入需要35秒。可能是什么原因?我在插入函数中使用相同的逻辑。你有什么想法吗?我使用VS 2008 sp1。

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

公共函数CR_KAMPANYA_MUSTERI_I(ByVal f_Line()As String,ByRef myComm As SqlCeCommand,ByRef rs As SqlCeResultSet,ByRef rec As 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

1 个答案:

答案 0 :(得分:0)

好吧,我发现了问题。我错了CR_MUS。我每次都在疯狂cr_mus因为我不会使p_CR_MUS = false。而且还增加进度条值也会降低性能。所以现在我没有问题。