..net 2.0 -
I've been getting a very strange error on my websites I can't track
down. It only happens occasionally, and continues until IIS is reset.
The error happens on line 10: Dim product As Product =
LoadProduct(row.Row)
It looks like row.Row is not being found in the view
We're caching the data - could this be related to the cache being
released and not fully repopulating itself? The code for
GetAllProductsDataSet() is the second set of code. Are there any
obvious errors, or a better way to handle it? Thanks
Error received: Object reference not set to an instance of an object.
This is the code the error happens on (line 10):
1 Dim ds As DataSet = GetAllProductsDataSet()
2 Dim products As New List(Of Product)
3 Dim myView As DataView
4 myView = ds.Tables(0).DefaultView
5 myView.Sort = sort
6 If Not "".Equals(filter) Then
7 myView.RowFilter = filter
8 End If
9 For Each row As DataRowView In myView
10 Dim product As Product = LoadProduct(row.Row)
11 If Not product Is Nothing AndAlso Not
products.Contains(product) Then
12 products.Add(product)
13 End If
14Next
GetAllProductsDataSet()
1 Dim cacheKey As String = "AllProducts-DataSet"
2 Dim ds As New DataSet()
3 ds = CType(Item(cacheKey), DataSet)
4 If ds Is Nothing Then
5 Dim ds2 As New DataSet
6 Using conn As SqlConnection = GetConnection(connstring)
7 Dim cmd As SqlCommand = New SqlCommand(storeproc, conn)
8 cmd.CommandType = CommandType.StoredProcedure
9
10 Dim da As New SqlDataAdapter(cmd)
11
12 Try
13 conn.Open()
14 da.Fill(ds2, "AllProducts")
15 Catch ex As Exception
16 Throw ex
17 Finally
18 If Not conn Is Nothing Then
19 conn.Close()
20 End If
21 End Try
22 End Using
23 ds = ds2
24 AddToCache(cacheKey, ds,
System.Web.Caching.CacheItemPriority.NotRemovable, 300)
25 End If
26 Return ds
thanks - Susan