This is a migrated thread and some comments may be shown as answers.

RadGrid + EnableViewState=False + DataReader = Invalid attempt to call FieldCount when reader is closed.

1 Answer 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin Warnke
Top achievements
Rank 1
Kevin Warnke asked on 10 Dec 2009, 05:53 AM
I've dumbed down my page about as much as I can.

I'm setting the DataSource of my RadGrid to the EL4 Database.ExecuteReader result.
Then I'm calling DataBind.

When I have EnableViewstate=true all works fine.

When I set EnableViewstate=false it fails (error below).

Any thoughts?  Anyone seen this before?

Thanks,
Kevin

Server Error in '/InternalAspx' Application.

 


 

Invalid attempt to call FieldCount when reader is closed.

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.InvalidOperationException: Invalid attempt to call FieldCount when reader is closed.

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:

[InvalidOperationException: Invalid attempt to call FieldCount when reader is closed.]
   System.Data.SqlClient.SqlDataReader.get_FieldCount() +4872808
   System.Data.Common.DbEnumerator.BuildSchemaInfo() +19
   System.Data.Common.DbEnumerator.MoveNext() +156
   Telerik.Web.UI.GridResolveEnumerable.GetCollectionItemType(Boolean noItemsInEnumerator, Type& collectionItemType, Object& collectionFirstObject) +210
   Telerik.Web.UI.GridResolveEnumerable.ParseProperties() +90
   Telerik.Web.UI.GridResolveEnumerable.Initialize() +13
   Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized() +20
   Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +158
   Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +129
   Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +383
   Telerik.Web.UI.GridTableView.get_ResolvedDataSource() +141
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +33
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +4
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +239
   Telerik.Web.UI.RadGrid.DataBind() +80
   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +2121
   Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +145
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

 


 

Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 15 Dec 2009, 10:04 AM
Hi Kevin,

Can you please verify that you are not closing the DataReader instance prematurely? The earliest point in which you can close the reader is inside DataBound event. More information on the subject can be found here.

Sincerely yours,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Kevin Warnke
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or