Last post Jul 18, 2017 08:07 AM by Deepak Panchal
Jul 17, 2017 07:26 AM|david39ni|LINK
I am getting a strange error in a vb.net application I have never got it in c# its the following
[InvalidOperationException: Invalid attempt to read when no data is present.]
System.Data.SqlClient.SqlDataReader.CheckDataIsReady(Int32 columnIndex, Boolean allowPartiallyReadColumn, Boolean permitAsync, String methodName) +2229940
System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn) +55
System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) +41
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) +78
Galgorm.Category.PopulateCategoryItems() in C:\Websites\galgormgroup_demo\dynamic\Category.aspx.vb:707
Galgorm.Category.Page_Load(Object sender, EventArgs e) in C:\Websites\galgormgroup_demo\dynamic\Category.aspx.vb:142
System.Web.UI.Control.OnLoad(EventArgs e) +109
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4498
Now I checked the code and there is indead a otitleReader.Read event at the top of the code so I no its not the case that the reader is not being read is there anything else I could look for that could cause this error.
If oTitleReader("web_description").ToString <> "" Then
Jul 17, 2017 07:54 AM|PatriceSc|LINK
And are you testing the value returned by the Read function? It's likely false meaning that for now your query doesn't return any row. If it ca happen test fi
Jul 17, 2017 10:45 AM|david39ni|LINK
But surely a harrows check a the start of page should be ok for that should it not?
Jul 17, 2017 10:57 AM|PatriceSc|LINK
What are you checking? Show the reading code.
I suspect you do call Read but without checking the return value. If it is expected you have to take some measure to handle this case. Else you perhaps have some issue in your WHERE clause.
Jul 18, 2017 08:07 AM|Deepak Panchal|LINK
it is possible that when you reached to the last record after that you are trying to read the data. so there is no data and you got this error.
you can try to check this in your code.
SQL Data Reader: Invalid attempt to read when no data is present
Invalid attempt to read when no data is present