This might seem like a weird problem. I have a website which lists out projects that need to be picked up by the users on the website; They complete the necessary actions for the project and mark that project as being completed. Each of these projects has
a unique id (that is devised using some formulae and naming-conventions.... not imp). On this website, whenever the user logs in, s/he sees the list of projects that needs to be completed. This is shown in a gridview and the project id column is a hyperlink
so that when they click on it they are taken to a new page that shows the details of the project.
Now comes the fun part. When the user is being taken to this new page where s/he sees the details of the project, I am getting the unique id for the project from the url, looking up its details from the database, putting it in an sqldatareader, and if the
reader.hasrows, then i am getting reader.getvalue(colNum).tostring and putting it in whichever fields i need. There is also another gridview in this new page where i am loading some more details of the same project (again querying the database, putting the
values in an sqldatareader, setting the datasource of the gridview to the datareader and then doing a gridview.databind(). Everything works perfectly when i am testing it. But when i publish the portal onto our production server, my users randomly get exceptions
like "A field or property with the name 'xxxx' was not found on the selected datasource" (meaning it was not able to find the column, but i know the column is there). They sometimes even get "Index was outside the bounds of the array" at the line [System.Data.SqlClient.SqlDataReader.GetValue(Int32
i)].... thats right on a reader.getvalue(colNum) line !! I am checking whether or not the reader.isDBNull(colnum) before trying to read value from it.
The problem is no that the error is occuring. The problem is that it is occurring RANDOMLY for the users. For instance, if they click the project ID and get the error, they click 'Back' button in the browser and again click on the project ID, this time the
new page opens up all ok!! and since this is a random behavior, i cant even find the root cause, because on my test environment i dont always get the error!!
Any ideas why this RANDOM behavior or how i can go about finding the root cause?
That is the problem! Its not one error message. Sometimes it says it is not able to find certain columns in the sql query, but many times it is an index out of bounds error. Here is an example:
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout) +5070412
System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +19
pagename.getDetails(String projID) in pagename.aspx.cs:1938
pagename.Page_Load(Object sender, EventArgs e) in pagename.aspx.cs:50
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
According to the description above, it seems like that the index you are using is bigger than the defined array size. In order to resolve your issue, please set a breakpoint into the code and find the main issue at first. Then set the rules of your loop
which stop index out of bounds exceptions occurring.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
parle_g
Member
7 Points
8 Posts
SQL Server RANDOMLY throwing errors
Jan 23, 2013 08:45 PM|LINK
Hi,
This might seem like a weird problem. I have a website which lists out projects that need to be picked up by the users on the website; They complete the necessary actions for the project and mark that project as being completed. Each of these projects has a unique id (that is devised using some formulae and naming-conventions.... not imp). On this website, whenever the user logs in, s/he sees the list of projects that needs to be completed. This is shown in a gridview and the project id column is a hyperlink so that when they click on it they are taken to a new page that shows the details of the project.
Now comes the fun part. When the user is being taken to this new page where s/he sees the details of the project, I am getting the unique id for the project from the url, looking up its details from the database, putting it in an sqldatareader, and if the reader.hasrows, then i am getting reader.getvalue(colNum).tostring and putting it in whichever fields i need. There is also another gridview in this new page where i am loading some more details of the same project (again querying the database, putting the values in an sqldatareader, setting the datasource of the gridview to the datareader and then doing a gridview.databind(). Everything works perfectly when i am testing it. But when i publish the portal onto our production server, my users randomly get exceptions like "A field or property with the name 'xxxx' was not found on the selected datasource" (meaning it was not able to find the column, but i know the column is there). They sometimes even get "Index was outside the bounds of the array" at the line [System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)].... thats right on a reader.getvalue(colNum) line !! I am checking whether or not the reader.isDBNull(colnum) before trying to read value from it.
The problem is no that the error is occuring. The problem is that it is occurring RANDOMLY for the users. For instance, if they click the project ID and get the error, they click 'Back' button in the browser and again click on the project ID, this time the new page opens up all ok!! and since this is a random behavior, i cant even find the root cause, because on my test environment i dont always get the error!!
Any ideas why this RANDOM behavior or how i can go about finding the root cause?
Regards,
oned_gk
All-Star
31515 Points
6433 Posts
Re: SQL Server RANDOMLY throwing errors
Jan 23, 2013 09:24 PM|LINK
oned_gk
All-Star
31515 Points
6433 Posts
Re: SQL Server RANDOMLY throwing errors
Jan 23, 2013 09:25 PM|LINK
parle_g
Member
7 Points
8 Posts
Re: SQL Server RANDOMLY throwing errors
Jan 23, 2013 10:13 PM|LINK
That is the problem! Its not one error message. Sometimes it says it is not able to find certain columns in the sql query, but many times it is an index out of bounds error. Here is an example:
makwei88
Member
498 Points
115 Posts
Re: SQL Server RANDOMLY throwing errors
Jan 23, 2013 10:57 PM|LINK
create a sql server profiler on to check which query was running when the this happen.
oned_gk
All-Star
31515 Points
6433 Posts
Re: SQL Server RANDOMLY throwing errors
Jan 24, 2013 12:38 AM|LINK
Maybe you have looping problem, forget to stop looping if the value doesnot exist.
You need to post your sample code to point your problem
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: SQL Server RANDOMLY throwing errors
Jan 30, 2013 04:19 AM|LINK
Hi,
According to the description above, it seems like that the index you are using is bigger than the defined array size. In order to resolve your issue, please set a breakpoint into the code and find the main issue at first. Then set the rules of your loop which stop index out of bounds exceptions occurring.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store