473,569 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 connectionStrin g As String =
WebConfig.Conne ctionString
Dim connection As SqlConnection = New
SqlConnection(c onnectionString )
Dim adapter As SqlDataAdapter = New
SqlDataAdapter( "SELECT applicationID FROM pvtProductAppli cation WHERE
productID = " + Request.QuerySt ring("prodId"), connection)
Dim dataSet As DataSet = New DataSet()
connection.Open ()
adapter.Fill(da taSet)
ApplicationRepe ater.DataSource = dataSet
ApplicationRepe ater.DataBind() /* error here */
connection.Clos e()

and I have a ApplicationRepe ater_ItemCreate d 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 5954
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**********@g mail.comwrote in message
news:51******** *************** ***********@b64 g2000hsa.google groups.com...
Hi

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

In my Page_Load, I have the following code:

Dim connectionStrin g As String =
WebConfig.Conne ctionString
Dim connection As SqlConnection = New
SqlConnection(c onnectionString )
Dim adapter As SqlDataAdapter = New
SqlDataAdapter( "SELECT applicationID FROM pvtProductAppli cation WHERE
productID = " + Request.QuerySt ring("prodId"), connection)
Dim dataSet As DataSet = New DataSet()
connection.Open ()
adapter.Fill(da taSet)
ApplicationRepe ater.DataSource = dataSet
ApplicationRepe ater.DataBind() /* error here */
connection.Clos e()

and I have a ApplicationRepe ater_ItemCreate d 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
5200
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. ---------------------------------------------------------------------------- ---- Invalid attempt to read when no data is present. Description: An...
0
1569
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 PopulateForm(ByVal MyOrderDetails As MyChannel.OrderDetails) Me.lblOrderID.Text = CStr(MyOrderDetails.OrderID)
2
5046
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 IDataReader = GetReader() Dim chart As New LineChart()
3
3025
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 = objCommand.ExecuteReader(CommandBehavior.CloseConnection); datalistoutput.DataSource = objDataReader;
4
12349
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 present which is correct. The line works when data is in the row. But shouldn't the
1
19761
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 SqlParameter("@ThreadID", SqlDbType.Int) SqlParam(0).Value = ThreadID
4
3466
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 values I get "Invalid attempt to read when no data is present". private void GetLotIDPriorityFromLot(string aLotDesc, out int aLotID, out...
2
6929
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 problem with this code: Invalid attempt to Read when reader is closed at line: While dtreader.Read() Thanks for help
1
1881
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 another page the script works yielding the desired records BUT WHEN YOU CALL THE SCRIPT AGAIN WHEN ATTEMPTING TO CALL THE SAME PAGE (PASSING...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.