Я не могу понять, почему отправка параметров для функции вставки работает медленно в .net compact framework.Проблема производительности в .Net compact framework
Forexample следующий код вставки в течение 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
Но когда я отправить параметры, а, б, к югу вставки, этот код завершается в пределах 13 seconds.What делает снижение производительности?
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
Это вставка к югу в классе дб
Public Class 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
конец класса
2 целых копии в стек? – 2009-11-02 18:53:57
Ненужная попытка/улов? – 2009-11-02 18:55:07
Вырыть профайлер и посмотреть? – 2009-11-02 18:55:56