Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 95383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:38:59+00:00 2026-05-10T23:38:59+00:00

So, I’m trying to use ADO.NET to stream a file data stored in an

  • 0

So, I’m trying to use ADO.NET to stream a file data stored in an image column in a SQL Compact database.

To do this, I wrote a DataReaderStream class that takes a data reader, opened for sequential access, and represents it as a stream, redirecting calls to Read(…) on the stream to IDataReader.GetBytes(…).

One ‘weird’ aspect of IDataReader.GetBytes(…), when compared to the Stream class, is that GetBytes requires the client to increment an offset and pass that in each time it’s called. It does this even though access is sequential, and it’s not possible to read ‘backwards’ in the data reader stream.

The SqlCeDataReader implementation of IDataReader enforces this by incrementing an internal counter that identifies the total number of bytes it has returned. If you pass in a number either less than or greater than that number, the method will throw an InvalidOperationException.

The problem with this, however, is that there is a bug in the SqlCeDataReader implementation that causes it to set the internal counter to the wrong value. This results in subsequent calls to Read on my stream throwing exceptions when they shouldn’t be.

I found some infomation about the bug on this MSDN thread.

I was able to come up with a disgusting, horribly hacky workaround, that basically uses reflection to update the field in the class to the correct value.

The code looks like this:

    public override int Read(byte[] buffer, int offset, int count)     {         m_length  = m_length ?? m_dr.GetBytes(0, 0, null, offset, count);          if (m_fieldOffSet < m_length)         {             var bytesRead = m_dr.GetBytes(0, m_fieldOffSet, buffer, offset, count);             m_fieldOffSet += bytesRead;              if (m_dr is SqlCeDataReader)             {                 //BEGIN HACK                 //This is a horrible HACK.                     m_field = m_field ?? typeof (SqlCeDataReader).GetField('sequentialUnitsRead', BindingFlags.NonPublic | BindingFlags.Instance);                     var length = (long)(m_field.GetValue(m_dr));                     if (length != m_fieldOffSet)                     {                            m_field.SetValue(m_dr, m_fieldOffSet);                     }                 //END HACK             }              return (int) bytesRead;         }         else         {             return 0;         }     } 

For obvious reasons, I would prefer to not use this.

However, I do not want to buffer the entire contents of the blob in memory either.

Does any one know of a way I can get streaming data out of a SQL Compact database without having to resort to such horrible code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:38:59+00:00Added an answer on May 10, 2026 at 11:38 pm

    Actually, I decided to fix the problem by just not storing blobs in the database to begin with.

    This eliminates the problem (I can stream data from a file), and also fixes some issues I might have run into with Sql Compact’s 4 GB size limit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.