Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cached DataSet not working

Status
Not open for further replies.

Modica82

Technical User
Jan 31, 2003
410
GB
Hi all,

I have a page where i want to cache a dataset for 30 seconds. When the dataset is not in Cache the page loads fine and it shows my data. Reloading the page, all the data binded to the grid dissapears. I know that the cached data set is in memory and it contains the same number of rows as the dataset would, but for some reason the data does not appear and i have no idea why, could someone have a look at my code and see if anything jumps out at them??????

Code:
    Private Sub BindWebData(ByVal index As Integer, ByVal sort As String)

        'Set sort item in sort text box, used for header formatting
        txtSort.Text = index & ", " & Trim(Mid(sort, sort.IndexOf(" ") + 2, 4))

        'Get Invoices DataSet
        'Create new dataset object to hold data returned from Web Service
        'Dim ds As New DataSet
        Dim dsName As String = "InvoiceDataSet" & CType(Context.User.Identity, CustomIdentity).Code

        If Cache(dsName) Is Nothing Then
            ds = GetInvoicesDataSet()

            '===Absolute expiration of Debtor DataSet Cache===
            Cache.Insert(dsName, ds, Nothing, _
                          DateTime.Now.AddSeconds(30), _
                           Cache.NoSlidingExpiration)

        Else
            ds = CType(Cache(dsName), DataSet)
        End If

        'Do DataSet Sorting
        Dim dv As New DataView
        dv = ds.Tables(0).DefaultView
        dv.Sort = sort

        dgInvoices.DataSource = dv
        dgInvoices.DataBind()

    End Sub

Thanks,

Rob

---------------------------------------
 
Is ViewState disabled for the page? When in the page lifecycle do you call this method? Is the DataGrid dynamically created?
 
Hi BoulderBum,

1) ViewState is not disbled
2) The call is made on page load, but is only done when it is not a postback.
3) i am not 100% sure what you mean here, but i have just created a dataset, created the columns using the property builder and bind the dataset to it.

Still not sure why this is happening, as the Dataset is in cache, becuase i can output the number of rows (row count) when the If Cache(dsName) Is Nothing Then is false and it runs the get DataSet from cache segment of the code, it just doesnt seem to want to bind to my grid???

Rob

---------------------------------------
 
>> The call is made on page load, but is only done when it is not a postback.


the grid has to be bound every time there is a postback if it has not been stored in view state.

If it comes back empty then as BoulderBum said, there could be a view state issue.

just to test this, call the binding function every time there is post back and see if it binds...

Known is handfull, Unknown is worldfull
 
Hi VbKris,

The thing is the the grid will be bound each time becuase in reality there is no postback on this page. The page gets launched from a button click which opens up a popup, but there are no server side controls on the page that will cause a postback, so everytime this page is generated the code is getting run. The funny thing is, i can count the number of rows in the Cached Dataset, and through debugging know that it it is hitting the code, it just doesnt seem to want to bind to my grid and i have no idea why?????

Rob

---------------------------------------
 
and how about the row count returned by the DataView? is the data view also returning the correct count???

Known is handfull, Unknown is worldfull
 
Yeah it does,

Response.Write(dv.Table.Rows.Count)

returns 861, the same is does the first time when the dataset is not in cache. I have no idea why it is not binding, i am very confused!!

Rob

---------------------------------------
 
I have noticed on thing. I do have a seperate web.config file in this directory, that is not the same as the default one. Is there anything in the web.config that i could be missing, this one is very basic.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
  
	<!--<customErrors defaultRedirect="~/Error.aspx" mode="On" />-->
	<customErrors mode="RemoteOnly" />

    <authorization>
        <deny users="?" />
    </authorization>

    <!--  GLOBALIZATION
          This section sets the globalization settings of the application. 
    -->
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />

  </system.web>
</configuration>

---------------------------------------
 
That shouldn't matter. It's possible that the cache is getting invalidated before you bind because the code block you have isn't threadsafe.

This will help if such is the case:

Code:
'fetch and hold a reference to the potentially cached item
ds = CType(Cache(dsName), DataSet)

'if there was no item, fetch it from GetInvoicesDataSet()
'and cache it
If ds Is Nothing Then
   ds = GetInvoicesDataSet()

   '===Absolute expiration of Debtor DataSet Cache===
   Cache.Insert(dsName, ds, Nothing, _
   DateTime.Now.AddSeconds(30), _
                           Cache.NoSlidingExpiration)
End If

'use DataSet here.
 
Hi Boulderbum,

Still no luck, the second time the page loads and the item is in cache even though it grabs it from the Cache it does not bind it to the DataGrid, which is really strange. This is starting to get very fustrating :-(.

Anymore ideas??

Rob

---------------------------------------
 
hi,

one more thing, try finding the item count of the datagrid after binding it.

it may be that some other code is overriding this DataBind. immediately after databind check the item count of the grid...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top