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. Database & SysAdmin
  3. Database
  4. How to retrieve binary file from Sql Server database to hard disk using SQL?

How to retrieve binary file from Sql Server database to hard disk using SQL?

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
6 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    Ahmad Safwat
    wrote on last edited by
    #1

    Hi, I'm Using: SELECT * FROM OPENROWSET(BULK 'G:\1.jpg', SINGLE_BLOB) to save binary files from hard disk to sql server database Now I need an SQL code to retrieve binary file from Sql Server database to hard disk

    A P 2 Replies Last reply
    0
    • A Ahmad Safwat

      Hi, I'm Using: SELECT * FROM OPENROWSET(BULK 'G:\1.jpg', SINGLE_BLOB) to save binary files from hard disk to sql server database Now I need an SQL code to retrieve binary file from Sql Server database to hard disk

      A Offline
      A Offline
      Ahmad Safwat
      wrote on last edited by
      #2

      heeeeeeeeey

      1 Reply Last reply
      0
      • A Ahmad Safwat

        Hi, I'm Using: SELECT * FROM OPENROWSET(BULK 'G:\1.jpg', SINGLE_BLOB) to save binary files from hard disk to sql server database Now I need an SQL code to retrieve binary file from Sql Server database to hard disk

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I just SELECT it and use a FileStream to write it. Here's an example:

        byte[] content = (byte[]) ds [ 1 ].Rows [ i ] [ "FileContent" ] ;

        fs.Write ( content , 0 , content.Length ) ;

        fs.Close() ;

        ds is a DataSet, and fs is the FileStream.

        L 1 Reply Last reply
        0
        • P PIEBALDconsult

          I just SELECT it and use a FileStream to write it. Here's an example:

          byte[] content = (byte[]) ds [ 1 ].Rows [ i ] [ "FileContent" ] ;

          fs.Write ( content , 0 , content.Length ) ;

          fs.Close() ;

          ds is a DataSet, and fs is the FileStream.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          that is not really streaming anything, so I'd recommend a simple File.WriteAllBytes(). BTW: I'm a bit puzzled by the ds[**1**] part... :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          P 1 Reply Last reply
          0
          • L Luc Pattyn

            that is not really streaming anything, so I'd recommend a simple File.WriteAllBytes(). BTW: I'm a bit puzzled by the ds[**1**] part... :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Luc Pattyn wrote:

            File.WriteAllBytes().

            In the case I quoted, I had to check whether or not a file by the chosen name existed first. There's no point creating the file if it already exists. So I use a FileInfo to check Exists and simply use its Open method to get a FileStream.

            Luc Pattyn wrote:

            the ds[1] part

            refers to the oneth DataTable in the DataSet -- the set of files I want to create.

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              Luc Pattyn wrote:

              File.WriteAllBytes().

              In the case I quoted, I had to check whether or not a file by the chosen name existed first. There's no point creating the file if it already exists. So I use a FileInfo to check Exists and simply use its Open method to get a FileStream.

              Luc Pattyn wrote:

              the ds[1] part

              refers to the oneth DataTable in the DataSet -- the set of files I want to create.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              :thumbsup:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              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