.Net紧凑框架中的性能问题

时间:2009-11-02 18:52:26

标签: .net vb.net exception-handling

我无法理解为什么发送参数到插入函数在.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 class

中的insert sub

公共类Db

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

结束课

1 个答案:

答案 0 :(得分:0)

我会在设备上仔细检查您的安装。让它混淆起来很容易。谷歌推出该产品的新方法是SQL Server Compact。

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

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