Reputation: 1001
I am facing an issue in ASP.NET Application which is in production now. I am using SQL Server 2008 Database and IIS 7.0.
My issue is: My website is running great for sometime, but after sometime it is throwing 'An unhandlednException". The Exception message is as follows
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'AddDate'.
But, there a field in the database with the name 'AddDate'.
This exception is occurring randomly and after sometime the website is running again normally by itself or when I recycle the application pool
I am unable to find out the cause for this behavior.
Please help me out in this regard. Thanks in advance....
HTML Code:
<asp:Repeater ID="rptrNewsTitles" runat="server">
<ItemTemplate>
<li class="news-item"><font style="font: 11px 'verdana'; color:#b5202b"><%#(Convert.ToDateTime(Eval("AddDate")).ToUniversalTime().Equals(DateTime.Now.ToUniversalTime())) ? " " + Convert.ToDateTime(Eval("AddDate")).ToUniversalTime().ToShortTimeString() : " " + Convert.ToDateTime(Eval("AddDate")).ToString("dd MMM yyyy")%> : </font><a href='showsubject.aspx?id=<%# Eval("subjectid")%>' style="text-decoration:none;"><%#Eval("SubjectTitle") %></a></li>
</ItemTemplate>
</asp:Repeater>
C# Code :
DataTable dt = new DataTable();
dt = ControlsDB.GetTableFromProc("GetNewsTitles", new string[] { "@Lang" }, new SqlDbType[] { SqlDbType.NVarChar }, new object[] { "En" }, conn);
rptrNewsTitles.DataSource = dt;
rptrNewsTitles.DataBind();
Fields returned from the procedure:
SubjectID, SubjectTitle, SubjectDetails, AddDate, Category, ViewsNo, AddedBy, Tip, Active, SubjectLanguage, Photo, SubjectBrief, HotNews, Country, CountryID, CountryName, CountryComment, CountryFlag, Code, Active, Lang
Thank you
Upvotes: 0
Views: 1873
Reputation: 13975
There are any number of possibilities. Here are a few:
If your procedure has complex logic, including IF-THEN-ELSE logic, you may once in a while be executing a SELECT that omits that field, or gives it a different alias.
If ControlsDB.GetTableFromProc
works by first instantiating (new-ing) a DataTable
and then filling it from a SqlDataAdapter
, which seems to be a common practice, it's possible that for any number of reasons (timeouts due to database lock is one quite likely possibility) the table is not getting filled from the proc but the method is still returning the DataTable
. This would give you a DataTable
with no columns, which would certainly throw that error if you attempted to bind to it.
In order for that to be happening you would need to be catching and suppressing the SQL error that would have happened on the SqlDataAdapter.Fill
, but still be returning the DataTable
.
Upvotes: 1