473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Invalid attempt to call FieldCount when reader is closed

Hi

I have a problem with a repeater and a data connection.

In my Page_Load, I have the following code:

Dim connectionString As String =
WebConfig.ConnectionString
Dim connection As SqlConnection = New
SqlConnection(connectionString)
Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT applicationID FROM pvtProductApplication WHERE
productID = " + Request.QueryString("prodId"), connection)
Dim dataSet As DataSet = New DataSet()
connection.Open()
adapter.Fill(dataSet)
ApplicationRepeater.DataSource = dataSet
ApplicationRepeater.DataBind() /* error here */
connection.Close()

and I have a ApplicationRepeater_ItemCreated that also opens a data
connection and closes it. The error is raised as indicated above.

Can someone please help??

Thanks, Mark
Jun 27 '08 #1
1 5931
Hi,

are these operations (this and the one in ItemCreated) sharing the same
connection object, which would get closed unexpectedly?

You don't need to optimize that way (sharing one connection on the page)
necessarily, since connection pooling in .NET will mostly take care of that
e.g it will get you connections efficiently and reuse them. Of course if
there could be numerous of conenction object creations, that's another thing

And with DataAdapters' you don't need to open the connection first before
calling Fill, it is opened for you.

Anyways, to give more exact advice, can you show the code in ItemCreated
using the connection?
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


<ma**********@gmail.comwrote in message
news:51**********************************@b64g2000 hsa.googlegroups.com...
Hi

I have a problem with a repeater and a data connection.

In my Page_Load, I have the following code:

Dim connectionString As String =
WebConfig.ConnectionString
Dim connection As SqlConnection = New
SqlConnection(connectionString)
Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT applicationID FROM pvtProductApplication WHERE
productID = " + Request.QueryString("prodId"), connection)
Dim dataSet As DataSet = New DataSet()
connection.Open()
adapter.Fill(dataSet)
ApplicationRepeater.DataSource = dataSet
ApplicationRepeater.DataBind() /* error here */
connection.Close()

and I have a ApplicationRepeater_ItemCreated that also opens a data
connection and closes it. The error is raised as indicated above.

Can someone please help??

Thanks, Mark

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brent Burkart | last post by:
Below is the error I am receiving. I have checked SQL Profiler and it is receiving the correct query which runs fine in Query Analyzer. Any ideas? Server Error in '/lockinsheet' Application....
0
by: CW | last post by:
I get this FieldCount error when I attempt to bind a datagrid with a dataset, not a datareader object. The code snippet is as belows: 'PopulateForm called in Page Load event Private Sub...
2
by: Patrick Olurotimi Ige | last post by:
Why do i get "Invalid attempt to FieldCount when reader is closed" Is the problem the way the datareader reads data as opposed to a dataset? When trying to compile this code:- Dim reader As...
3
by: Patrick Olurotimi Ige | last post by:
With the code below i get error:- Invalid attempt to read data when reader is closed. //Get a datareader SqlDataReader objDataReader; objDataReader =...
4
by: Dave | last post by:
I'm using a datareader to get data from an sql table. The line that gives the error is as follow, dtrReceivers.ToString() which gives the error, Invalid attempt to read when no data is...
1
by: sivam.solai | last post by:
Public Function GetTopLevelThreadName(ByVal ThreadID As Integer) As SqlDataReader Sp_Datasql = "WS_Get_TopLevelThreadName" SqlParam = New SqlParameter(0) {} Try SqlParam(0) = New...
4
by: MarkusR | last post by:
If I run the stored proc in the Query Analyzer this works and I get the expected result set back. However when I run it in my application I get a results set of one row but when I try to access the...
2
by: Chris | last post by:
Hi, i wrote this code for fetching data from a table using a stored procedure. The connection definition and opening are put in a class. The actual read of data occurs in code-behind. My...
1
Oodles Of Noodles
by: Oodles Of Noodles | last post by:
Hello fellow geeks I have a problem in my database iVB .Net program that is generating 'Error:Invalid attempt to read when no data is present.' The weird part is that when you call the page from...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.