Hi,
I'm working with netTiers for the first time and have had a fairly smooth ride so far but have encountered a rather frustrating problem which I need help with.
I'm using netTiers with an ASP.NET 2.0 project and to illustrate my problem I built a simple page. My entity is 'School' and so my page has a 'SchoolDataSource'.
<data:SchoolDataSource ID="dsSchools" EnableCaching=false runat=server CacheDuration="0" EnableViewState="False"><DeepLoadProperties Method="IncludeChildren" Recursive="False"></DeepLoadProperties></data:SchoolDataSource>
I add a Gridview using this datasource, displaying the id and name (schID and schName):
<asp:GridView ID="GridView1" runat="server" DataKeyNames="SchID" DataSourceID="dsSchools" AutoGenerateColumns="False" EnableViewState=false><Columns><asp:BoundField DataField="SchID" HeaderText="SchID" SortExpression="SchID" /><asp:BoundField DataField="SchName" HeaderText="SchName" SortExpression="SchName" /></Columns></asp:GridView>
I then add a SQL Data Source and another gridview against the same table, here using a simple SQL query:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT [schName], [schID] FROM [School]"></asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="schID" DataSourceID="SqlDataSource1" EnableViewState="False"><Columns><asp:BoundField DataField="schName" HeaderText="schName" SortExpression="schName" /><asp:BoundField DataField="schID" HeaderText="schID" InsertVisible="False" ReadOnly="True" SortExpression="schID" /></Columns></asp:GridView>
Finally I add a button to postback the page and cause it to redisplay the data, with the current datetime beneath it:
<asp:Button ID="Button1" runat="server" Text="Button" /><br /><%=Now()%>
This simple page works fine until I update the data using a SQL Query Analyzer session. I update the name of a particular row using a randomise function:
update School set schName='School '+cast(cast(rand()*10000 as integer) as varchar(10)) where schID=53
select schName from School where schID=53
If I run the above and then click the button on my page then I see the gridview which is bound to the Sql Data Source show the new schName value immediately. The gridview which is using the SchoolDataSource sometimes updates, but usually maintains the old value for a fair period of time (I've haven't been able to determine a pattern, sometimes its a few seconds, sometimes a number of minutes). ![Huh? [:^)]](/emoticons/emotion-18.gif)
Why is this happening? As far as I know I have no caching active and so I don't understand why the gridview doesn't show the updated data. I can repeat this over and over again with the same result.
More confusion is raised if I run SQL Profiler. Here I can see that the query behind the SchoolDataSource (and the SQL Data Source) is run everytime I press the button - as I would expect - but despite this the displayed data is still old. The profiler shows the following has been run each time:
SELECT
[schID],
[schName]
FROM
dbo.[School]
Select @@ROWCOUNT
AND
SELECT [schName], [schID] FROM [School]
Can anyone explain why I'm seeing this behaviour? I hope so; I need this to work and right now I'm stuck doing a very simple thing; trying to display current data from the database.
Please help...
Barry.