【问题标题】:Performance Problem in .Net compact framework.Net 紧凑框架中的性能问题
【发布时间】:2009-11-02 18:52:25
【问题描述】:

我不明白为什么在 .net 紧凑型框架中向插入函数发送参数运行缓慢。

例如以下代码在 2 秒内插入

    cn = New SqlCeConnection(strstring)
    cmd = New SqlCeCommand
    Dim rs As SqlCeResultSet
    cmd.Connection = cn
    cmd.CommandType = CommandType.TableDirect
    cn.Open()
    Dim rec As SqlCeUpdatableRecord
    Dim DB As New Db
    Dim a As Integer = 1
    Dim b As Integer = 2
    For i As Integer = 0 To 1000
        If i = 0 Then
            cmd.CommandText = "A"
            rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)
            rec = rs.CreateRecord()
        End If
        Try
            rec.SetValue(0, a)
            rec.SetValue(1, b)
            rs.Insert(rec
         Catch ex As Exception

        End Try


    Next

但是当我将参数 a 和 b 发送到插入子时,这段代码在 13 秒内完成。性能下降了什么?

 cn = New SqlCeConnection(strstring)
    cmd = New SqlCeCommand
    Dim rs As SqlCeResultSet
    cmd.Connection = cn
    cmd.CommandType = CommandType.TableDirect
    cn.Open()
    Dim rec As SqlCeUpdatableRecord

    For i As Integer = 0 To 1000
        If i = 0 Then
            cmd.CommandText = "A"
            cmd.CommandType = CommandType.TableDirect
            rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)
            rec = rs.CreateRecord()
        End If
        Try
            DB.Insert(1, 2, rs, rec)
        Catch ex As Exception

        End Try


    Next 

这是在 db 类中插入 sub

公共类数据库

Public Shared Sub Insert(ByVal a As Integer, ByVal b As Integer, ByRef rs As SqlCeResultSet, ByRef rec As SqlCeUpdatableRecord)
    Try
        rec.SetValue(0, a)
        rec.SetValue(1, If(b = String.Empty, DirectCast(DBNull.Value, Object), b))
        rs.Insert(rec)
    Catch ex As Exception

    End Try


End Sub

结束课程

【问题讨论】:

  • 2 个整数拷贝到堆栈?
  • 拿出分析器看看?
  • 你检查过其中一个没有抛出异常吗?
  • 没有例外,使用 try catch 不会减少。我猜堆栈的 2 个整数会变慢,我该如何防止呢?当我将整数视为空时,它不会改变。
  • 在代码中使用空的 try/catch 是一个非常糟糕的主意。您可以删除它们并再次测试吗?

标签: .net vb.net exception-handling


【解决方案1】:

我会仔细检查您在设备上的安装。很容易混淆。谷歌搜索产品的新方法是 SQL Server Compact。

由于 microsoft 决定更改移动/CE 空间中所有内容的名称,因此无法搜索帮助。是 Windows CE、Pocket PC、Windows Mobile 还是 Phone 7?是 SQL CE 还是 Sql Server Compact “Arrgh”!

也许这些链接会帮助下一个人。 MSDN Blog 或这个Technet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多