Sporadic Error: Cannot find table 0

P

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
 
S

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/
 
W

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?
 
P

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
 
S

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top