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

Exception "Invalid attempt to read when no data is present."

4 Answers 279 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jay
Top achievements
Rank 1
Jay asked on 08 Jul 2011, 07:29 PM
I am attempting to something similar to this:

public bool Persist()
    {
        using (Model context = new Model())
           {
                    IQueryable<Item> rs = (from d in context.Data select d);
                    TotalCount = rs.Count();
                    if (TotalCount <= 0) return false;
                 
                    foreach (Item r in rs)
                    {
                        // Additional Code
                       }
        }
    }

And after about 10% of the way through the foreach loop, it throws this exception:

Telerik.OpenAccess.Exceptions.DataStoreException: System.InvalidOperationException: Invalid attempt to read when no data is present.
   at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i)
   at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
   at OpenAccessRuntime.Data.BigIntConverter.ToInt32.Read(DataHolder& data)
   at OpenAccessRuntime.Relational.metadata.RelationalColumn.GetValue(DataHolder& data)
   at OpenAccessRuntime.Relational.RelationalGenericOID.CopyKeyFields(DataHolder& data)
   at OpenAccessRuntime.Relational.fetch.FopGetOID.fetch(FetchResult fetchResult, StateContainer stateContainer)
   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)
Processing 0: Data [0] System.InvalidOperationException: Invalid attempt to read when no data is present.
   at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i)
   at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
   at OpenAccessRuntime.Data.BigIntConverter.ToInt32.Read(DataHolder& data)
   at OpenAccessRuntime.Relational.metadata.RelationalColumn.GetValue(DataHolder& data)
   at OpenAccessRuntime.Relational.RelationalGenericOID.CopyKeyFields(DataHolder& data)
   at OpenAccessRuntime.Relational.fetch.FopGetOID.fetch(FetchResult fetchResult, StateContainer stateContainer)
   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer) ---> System.InvalidOperationException: Invalid attempt to read when no data is present.
   at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i)
   at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
   at OpenAccessRuntime.Data.BigIntConverter.ToInt32.Read(DataHolder& data)
   at OpenAccessRuntime.Relational.metadata.RelationalColumn.GetValue(DataHolder& data)
   at OpenAccessRuntime.Relational.RelationalGenericOID.CopyKeyFields(DataHolder& data)
   at OpenAccessRuntime.Relational.fetch.FopGetOID.fetch(FetchResult fetchResult, StateContainer stateContainer)
   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)
   --- End of inner exception stack trace ---
   at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
   at Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
   at OpenAccessRuntime.storagemanager.logging.LoggingStorageManager.fetchNextQueryResult(ApplicationContext context, RunningQuery runningQuery, Int32 skipAmount)
   at OpenAccessRuntime.DataObjects.SynchronizedPMProxy.getNextQueryResult(QueryResultWrapper aQrs, Int32 skipAmount)
   at OpenAccessRuntime.DataObjects.ForwardQueryResult.GetMoreDataIntoWindow(Int32 requestedIndex)
   at OpenAccessRuntime.DataObjects.ForwardQueryResult.InternalGetSparse(Int32 requestedIndex)
   at OpenAccessRuntime.DataObjects.ForwardQueryResult.get_Item(Int32 indexParam)
   at OpenAccessRuntime.DataObjects.SynchronizedQueryResult.get_Item(Int32 index)
   at Telerik.OpenAccess.RT.ListEnumerator.setCurrent(Int32 _pos)
   at Telerik.OpenAccess.RT.ListEnumerator.Move(Int32 relative)
   at Telerik.OpenAccess.RT.ListEnumerator.MoveNext()
   at Telerik.OpenAccess.Query.TypedEnumerator`1.System.Collections.IEnumerator.MoveNext()
   at Data.Persist() in C:\Project\Data.cs:line 194

I did attempt to follow the suggestions from this post, but the changes (editing the timeout in the Model Settings Dialog) didn't fix my problem. For reference, line 194 mentioned in the Stack track is the foreach loop line.

Any help would be greatly appreciated.

Jay

4 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 11 Jul 2011, 08:36 AM
Hi Jay,

can you please alter your code so that:

public
bool Persist() 
    using (Model context = new Model()) 
    
        IQueryable<Item> rs = (from d in context.Data select d); 
        TotalCount = 0;
        
        foreach (Item r in rs) 
        
            // Additional Code
            TotalCount++;
        
        return TotalCount > 0;
    

This will require one query less on the server. Also, could you tell us what the Item class/table has for fields/columns? Maybe it's one type that you do not use otherwise that is offending here.

All the best,
Thomas
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Jay
Top achievements
Rank 1
answered on 11 Jul 2011, 03:22 PM
Hi Thomas,

Here is the XML code from Model.rlinq for the class in question:

<orm:class name="Data" uniqueId="31e5f267-14bf-4098-8002-ceda660e1cb8" persistent-baseclass="Project.DataRun">
  <orm:table name="Data" />
  <orm:identity>
    <orm:key-generator name="autoinc" />
    <orm:single-field field-name="ID1" />
  </orm:identity>
  <orm:field name="Foo1" property="Foo" uniqueId="d1536712-85c8-468d-ab8b-c59e170c8a92" type="System.String">
    <orm:column name="foo" sql-type="varchar" length="255" ado-type="Varchar" />
  </orm:field>
  <orm:field name="Bar1" property="Bar" uniqueId="d67947f4-42eb-4e71-b782-deb7ca962ac7" type="System.String">
    <orm:column name="bar" sql-type="varchar" length="255" scale="0" ado-type="Varchar" />
  </orm:field>
  <orm:field name="Code21" property="Code2" uniqueId="624e6d43-1f5d-4551-a78b-e433686a7a1b" type="System.String">
    <orm:column name="code2" sql-type="varchar" length="2" scale="0" ado-type="Varchar" />
  </orm:field>
  <orm:field name="Desc1" property="Desc" uniqueId="0b2bcf44-8927-466e-8a49-6b1025dd2335" type="System.String">
    <orm:column name="desc" sql-type="varchar" length="255" scale="0" ado-type="Varchar" />
  </orm:field>
  <orm:field name="ID1" property="ID" uniqueId="29341ff5-8b86-4a83-9929-7139a3212c8a" type="System.Int32">
    <orm:column name="ID" sql-type="bigint" nullable="false" scale="0" primary-key="true" backend-calculated="true" ado-type="Int32" />
  </orm:field>
  <orm:field name="Type1" property="Type" uniqueId="a4e15aa2-a932-4516-8c1c-0cfb9f503730" type="System.String">
    <orm:column name="type" sql-type="varchar" length="255" scale="0" ado-type="Varchar" />
  </orm:field>
  <orm:field name="Value1" property="Value" uniqueId="93af5b4f-d60a-4c48-8b11-ff2f63ef6aa5" type="System.Byte">
    <orm:column name="value" sql-type="tinyint" nullable="false" scale="0" ado-type="Int16" />
  </orm:field>
  <orm:field name="DataRun.Created" property="Created" null-value="none" member-definition-type="Project.DataRun" type="System.DateTime">
    <orm:column name="created" sql-type="smalldatetime" scale="0" ado-type="DateTime" />
  </orm:field>
  <orm:field name="DataRun.Updated" property="Updated" null-value="none" member-definition-type="Project.DataRun" type="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]">
    <orm:column name="updated" sql-type="smalldatetime" nullable="true" scale="0" ado-type="DateTime" />
  </orm:field>
  <orm:field name="DataRun.UpdateCount" property="UpdateCount" member-definition-type="Project.DataRun" type="System.Int16">
    <orm:column name="UpdateCount" sql-type="smallint" length="0" scale="0" ado-type="" />
  </orm:field>
</orm:class>

As for the modification you mentioned above, there is need for the TotalCount variable within the addition code not being shown.

I appreciate the help.

Thanks,

Jay
0
Thomas
Telerik team
answered on 12 Jul 2011, 02:29 PM
Hello Jay,

 I still think that this is an environment issue, because the exception actually occurs in a SqlDataReader method IsDBNull, which should not raise such an exception. However, at least some of the settings in the .rlinq file are wrong:
(1) The ID column has sql-type bigint, and should therefore use ado-type Int64.
(2) The value column has sql-type tinyint and therefore should use ado-type Byte.

Also, I think that the ID column should use System.Int64 as field type. Can you change that and give it a try?
You could also look at the data in the MS Server Management Studio and see if there is the same behavior to be found.

Greetings,
Thomas
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Jay
Top achievements
Rank 1
answered on 20 Jul 2011, 03:40 PM
Hi Thomas,

Having made those changes you mentioned and recreating a few associations in the ORM model, the problem was resolved. I never truly understood what caused the problem but am glad it fixed.

Thanks,

Jay
Tags
Development (API, general questions)
Asked by
Jay
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Jay
Top achievements
Rank 1
Share this question
or