Home All Groups Group Topic Archive Search About

Sporadic Error: Cannot find table 0

Author
29 Jan 2005 4:39 PM
POL8985
The application is developed in ASP.Net with a SQL Server database.

Essentially, the application uses a single shared Connection object for
all users logged into the system.  The connection object is
opened/closed for each transaction.

The error - System.IndexOutOfRangeException: Cannot find table 0 -
occurs on one page that accepts a single piece of data from a textbox.
This data is then passed to the business logic classes (in VB.Net) and
is queried against the database.

According to the stack trace, the error occurs at:
System.Data.DataTableCollection.get_Item(Int32 index) +79

Out of 100 data entries, this error will appear once or twice.  Note
also that when the user enters the same piece of data that caused the
initial run-time error, the second entry executes OK!
Any suggestions?

Thanks:

Pat

Author
29 Jan 2005 4:55 PM
Sahil Malik
Pat,

The problem is in your logic. When that error occurs, you are getting a
dataset with no tables back.
At the very line the error happens, you can put checking code like this

if (Dataset.Tables.Count == 0)
  // show the user that no data was fetched
else
  // your current logic

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/



Show quote
"POL8985" <pol8***@njit.edu> wrote in message
news:1107016795.289246.6550@c13g2000cwb.googlegroups.com...
> The application is developed in ASP.Net with a SQL Server database.
>
> Essentially, the application uses a single shared Connection object for
> all users logged into the system.  The connection object is
> opened/closed for each transaction.
>
> The error - System.IndexOutOfRangeException: Cannot find table 0 -
> occurs on one page that accepts a single piece of data from a textbox.
> This data is then passed to the business logic classes (in VB.Net) and
> is queried against the database.
>
> According to the stack trace, the error occurs at:
> System.Data.DataTableCollection.get_Item(Int32 index) +79
>
> Out of 100 data entries, this error will appear once or twice.  Note
> also that when the user enters the same piece of data that caused the
> initial run-time error, the second entry executes OK!
> Any suggestions?
>
> Thanks:
>
> Pat
>
Author
29 Jan 2005 6:15 PM
W.G. Ryan eMVP
Like Sahil mentions- you should check the DataSet.Tables.Count property
before trying to access it - but why this is happening is also of concern.
As a general point - what benefit do you get from only having one connection
object shared throughout everything?

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
Show quote
"POL8985" <pol8***@njit.edu> wrote in message
news:1107016795.289246.6550@c13g2000cwb.googlegroups.com...
> The application is developed in ASP.Net with a SQL Server database.
>
> Essentially, the application uses a single shared Connection object for
> all users logged into the system.  The connection object is
> opened/closed for each transaction.
>
> The error - System.IndexOutOfRangeException: Cannot find table 0 -
> occurs on one page that accepts a single piece of data from a textbox.
> This data is then passed to the business logic classes (in VB.Net) and
> is queried against the database.
>
> According to the stack trace, the error occurs at:
> System.Data.DataTableCollection.get_Item(Int32 index) +79
>
> Out of 100 data entries, this error will appear once or twice.  Note
> also that when the user enters the same piece of data that caused the
> initial run-time error, the second entry executes OK!
> Any suggestions?
>
> Thanks:
>
> Pat
>
Author
29 Jan 2005 7:38 PM
Sahil Malik
In my opinion, there is no benefit of having a single connection object if
your underlying data provider supports connection pooling, and I am willing
to argue that point till the cows come home.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/


Show quote
"W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
news:OonAQ4iBFHA.1396@tk2msftngp13.phx.gbl...
> Like Sahil mentions- you should check the DataSet.Tables.Count property
> before trying to access it - but why this is happening is also of concern.
> As a general point - what benefit do you get from only having one
> connection
> object shared throughout everything?
>
> --
> W.G. Ryan MVP (Windows Embedded)
>
> TiBA Solutions
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "POL8985" <pol8***@njit.edu> wrote in message
> news:1107016795.289246.6550@c13g2000cwb.googlegroups.com...
>> The application is developed in ASP.Net with a SQL Server database.
>>
>> Essentially, the application uses a single shared Connection object for
>> all users logged into the system.  The connection object is
>> opened/closed for each transaction.
>>
>> The error - System.IndexOutOfRangeException: Cannot find table 0 -
>> occurs on one page that accepts a single piece of data from a textbox.
>> This data is then passed to the business logic classes (in VB.Net) and
>> is queried against the database.
>>
>> According to the stack trace, the error occurs at:
>> System.Data.DataTableCollection.get_Item(Int32 index) +79
>>
>> Out of 100 data entries, this error will appear once or twice.  Note
>> also that when the user enters the same piece of data that caused the
>> initial run-time error, the second entry executes OK!
>> Any suggestions?
>>
>> Thanks:
>>
>> Pat
>>
>
>
Author
29 Jan 2005 11:18 PM
POL8985
Thank you Sahil, WG for your suggestions.

Technically, the IndexOutOfRangeException should never occur because
the data being entered in the ASPX page is actually in the database
(and should return the corresponding set of records in my
DataSet.Table(0))!  We've actually never paid explicit attention to
connection pooling and hope this would be key to solving our problem.

Allow me to give you a bit more background into the application.

The ASP.Net application references two DLLs that provide 100% of the
business logic.  Each of these DLLs performs all SQL Server
transactions via a data access class we wrote.  Each DLL has one global
instance of this data access class (with the same connection string).
The data access class uses a single connection object that is
open/closed with each transaction.

I know that connection pooling is automatically handled by ADO.Net, but
how would I explicitly use it to solve this problem?
Thanks again:

Pat
Author
30 Jan 2005 1:34 AM
Sahil Malik
I doubt connection pooling will help solve the problem of not having a table
appear, where you expect it to.
Your best bet will still be to try and look at the tables collection just
before you get the error.

Regards ...
> The ASP.Net application references two DLLs that provide 100% of the
> business logic.  Each of these DLLs performs all SQL Server
> transactions via a data access class we wrote.  Each DLL has one global
> instance of this data access class (with the same connection string).
> The data access class uses a single connection object that is
> open/closed with each transaction.
.....

Again, close your connections as soon as possible, and open as late as
possible. I don't think you are doing that above.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/




Show quote
"POL8985" <pol8***@njit.edu> wrote in message
news:1107040695.387848.273990@z14g2000cwz.googlegroups.com...
> Thank you Sahil, WG for your suggestions.
>
> Technically, the IndexOutOfRangeException should never occur because
> the data being entered in the ASPX page is actually in the database
> (and should return the corresponding set of records in my
> DataSet.Table(0))!  We've actually never paid explicit attention to
> connection pooling and hope this would be key to solving our problem.
>
> Allow me to give you a bit more background into the application.
>
> The ASP.Net application references two DLLs that provide 100% of the
> business logic.  Each of these DLLs performs all SQL Server
> transactions via a data access class we wrote.  Each DLL has one global
> instance of this data access class (with the same connection string).
> The data access class uses a single connection object that is
> open/closed with each transaction.
>
> I know that connection pooling is automatically handled by ADO.Net, but
> how would I explicitly use it to solve this problem?
> Thanks again:
>
> Pat
>

AddThis Social Bookmark Button