Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Streaming binary data [modified]

Streaming binary data [modified]

Scheduled Pinned Locked Moved LINQ
csharpdatabaseasp-netlinqsysadmin
4 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Marynowski
    wrote on last edited by
    #1

    Hi, Is there any way to stream binary data from a SQL database using LINQ? In an ASP.NET application, I want to use a custom HTTP handler to get the binary data in small chunks and send it to the response stream. Otherwise, if I have a 150mb file to download, the web server will have to cache the entire file before the transfer even starts to the client! I am looking for something similar to the SQLDataReader.GetBytes() function, where I can get a few bytes at a time. Any help regarding this is appreciated. Thanks, --Mike

    modified on Thursday, March 27, 2008 6:05 PM

    P 1 Reply Last reply
    0
    • M Mike Marynowski

      Hi, Is there any way to stream binary data from a SQL database using LINQ? In an ASP.NET application, I want to use a custom HTTP handler to get the binary data in small chunks and send it to the response stream. Otherwise, if I have a 150mb file to download, the web server will have to cache the entire file before the transfer even starts to the client! I am looking for something similar to the SQLDataReader.GetBytes() function, where I can get a few bytes at a time. Any help regarding this is appreciated. Thanks, --Mike

      modified on Thursday, March 27, 2008 6:05 PM

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Off the top of my head (and I can't say I've looked into this) but you might be able to use a combination of Skip and Take to achieve this. The data would be mapped to a byte array, so it should (theoretically) be possible. Good luck.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        Off the top of my head (and I can't say I've looked into this) but you might be able to use a combination of Skip and Take to achieve this. The data would be mapped to a byte array, so it should (theoretically) be possible. Good luck.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        M Offline
        M Offline
        Mike Marynowski
        wrote on last edited by
        #3

        Hi, Mapping the data to a byte array would require using the Linq.Binary.ToArray() function, which would effectively load the entire array into memory before doing anything with it. Lets say I want the first 5 bytes: GSTDatabaseDataContext gstDatabase = new GSTDatabaseDataContext(); var fileData = (from f in gstDatabase.Files select f.Data).Single(); byte[] data = (from d in fileData.ToArray() select d).Take(5).ToArray(); [modified - added .ToArray() at the end of the last line] by using fileData's (which is a Linq.Binary type) ToArray() function, it means the ASP.NET server will load the entire array into memory from the SQL Server. My problem is that I want to get the data from the SQL server in small chunks so that I can stream it as it comes. Any suggestions? Why is it so damn difficult to find any information about LINQ online...I searched and searched and apparently nobody has a need to do this :confused: I don't understand. Even this LINQ forum has barely any posts. Is nobody using LINQ for anything?? lol

        modified on Friday, March 28, 2008 8:08 AM

        M 1 Reply Last reply
        0
        • M Mike Marynowski

          Hi, Mapping the data to a byte array would require using the Linq.Binary.ToArray() function, which would effectively load the entire array into memory before doing anything with it. Lets say I want the first 5 bytes: GSTDatabaseDataContext gstDatabase = new GSTDatabaseDataContext(); var fileData = (from f in gstDatabase.Files select f.Data).Single(); byte[] data = (from d in fileData.ToArray() select d).Take(5).ToArray(); [modified - added .ToArray() at the end of the last line] by using fileData's (which is a Linq.Binary type) ToArray() function, it means the ASP.NET server will load the entire array into memory from the SQL Server. My problem is that I want to get the data from the SQL server in small chunks so that I can stream it as it comes. Any suggestions? Why is it so damn difficult to find any information about LINQ online...I searched and searched and apparently nobody has a need to do this :confused: I don't understand. Even this LINQ forum has barely any posts. Is nobody using LINQ for anything?? lol

          modified on Friday, March 28, 2008 8:08 AM

          M Offline
          M Offline
          Mike Marynowski
          wrote on last edited by
          #4

          For those interested, I got my answer: You can get a DataReader from your LINQ query and do with it what you please. I stumbled upon this, which pointed me in the right direction: http://www.west-wind.com/WebLog/posts/141435.aspx[^] Happy coding! --Mike

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups