Compact Framework 中非常有趣的问题

发布于 2024-08-09 22:19:46 字数 3245 浏览 1 评论 0原文

我在将数据插入 sqlce 时遇到性能问题。我正在读取字符串并向我的表进行插入。在 LU_MAM 表中,我在 8 秒内插入 1000 条记录。在 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() 作为字符串,ByRef myComm 作为 SqlCeCommand,ByRef rs 作为 SqlCeResultSet,ByRef rec 作为 SqlCeUpdatableRecord) 作为字符串

    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

i have a performance problem while inserting data to sqlce.I'm reading string and making inserts to My tables.In LU_MAM table,i insert 1000 records withing 8 seconds.After Mam tables i make some inserts but my largest table is CR_MUS.When i want to insert record into CR_MUS,it takes too much time.CR_MUS has 2000 records and insert takes 35 seconds.What can be reason?I use same logic in my insert functions.Do u have any idea?I use 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

Public Function 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长伴 2024-08-16 22:19:46

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

ok,i found problem.I am wrong in CR_MUS.I am craeating cr_mus everytime because i dont make p_CR_MUS=false.And Also increasing progressbar value decrease performance very much too.So now i dont have problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文