I'm currently using custom business components that return custom business entities with ObjectDataSource in ASP.NET and find that i'm getting unnecessary queries to the DB. What i have is the following hierarchy in the page:
Now, in order to get the Panel to bind the visible property i need to call either Page.DataBind or DataBind on the panel itself. But, regardless of which one i call because the DataBind method is invoked recursively it calls the DataBind on the DataList
too and that results in the Select method of the ODS being called. But of coarse the automatic binding also calls the select method, and i end up with 2 queries absolutely un-necessarily....grrr.... (I use SQL Profile to see what's getting executed).
Now i've been thinking about how to overcome this. One option i though of was setting caching for a small period of time on the ODS (like 1 second), but that's not a good solution and has potential to not work as expected all the time (e.g. if there is
a high load on the server). The other option is to try and set the DataSource or DataSourceID to the ObjectDataSource control after calling the DataBind on the page. This seems better, but still not good. In fact i tried it and called databind followed
by setting the methods and got no records, then i swapped and set the DataList and FormView first followed by calling DataBind and still got 2 queries on the DB...grrr... this is so frustrating.
What's even worse is if you stick and ODS in a UserControl which is a few levels down in the control hierarchy. As a result you get the Select method being called multiple times because the parent controls still need to perform the data binding and the
only way i know of doing that is by calling the DataBind method on them.
Does anyone have any ideas or recommendations? What would be the best approach here? Should i just drop using the stupid ODS way of doing things and go back to good old code for everything that gives me the precise control over what happens and when?
Is there maybe like some way to turn off automatic databinding for the ODS, so that it would only do it when u call DataBind?
nicksh
Member
55 Points
11 Posts
ObjectDataSource performing unnecessary quieries
Mar 14, 2006 11:48 AM|LINK
Hi guys,
I'm currently using custom business components that return custom business entities with ObjectDataSource in ASP.NET and find that i'm getting unnecessary queries to the DB. What i have is the following hierarchy in the page:
<asp:Panel ... Visible='<%# PageProperty %>'>
<asp:DataList ... DataSourceID="ObjectDataSourceControl" >...</asp:DataList>
<asp:FormView ... DataSourceID="ObjectDataSourceControl">...</asp:DataList>
</asp:Panel>
Now, in order to get the Panel to bind the visible property i need to call either Page.DataBind or DataBind on the panel itself. But, regardless of which one i call because the DataBind method is invoked recursively it calls the DataBind on the DataList too and that results in the Select method of the ODS being called. But of coarse the automatic binding also calls the select method, and i end up with 2 queries absolutely un-necessarily....grrr.... (I use SQL Profile to see what's getting executed).
Now i've been thinking about how to overcome this. One option i though of was setting caching for a small period of time on the ODS (like 1 second), but that's not a good solution and has potential to not work as expected all the time (e.g. if there is a high load on the server). The other option is to try and set the DataSource or DataSourceID to the ObjectDataSource control after calling the DataBind on the page. This seems better, but still not good. In fact i tried it and called databind followed by setting the methods and got no records, then i swapped and set the DataList and FormView first followed by calling DataBind and still got 2 queries on the DB...grrr... this is so frustrating.
What's even worse is if you stick and ODS in a UserControl which is a few levels down in the control hierarchy. As a result you get the Select method being called multiple times because the parent controls still need to perform the data binding and the only way i know of doing that is by calling the DataBind method on them.
Does anyone have any ideas or recommendations? What would be the best approach here? Should i just drop using the stupid ODS way of doing things and go back to good old code for everything that gives me the precise control over what happens and when? Is there maybe like some way to turn off automatic databinding for the ODS, so that it would only do it when u call DataBind?
</div>pkellner
All-Star
24042 Points
3625 Posts
ASPInsiders
Moderator
MVP
Re: ObjectDataSource performing unnecessary quieries
Mar 15, 2006 05:11 AM|LINK
http://peterkellner.net
Microsoft MVP • ASPInsider