'Best way to retrieve pdf attachments saved as varbinary(max) from SQL Server and save to a local drive using C#

I have few thousands attachments saved in a SQL Server database with column datatype varbinary(max). I want to retrieve all these files and save them to a local drive.

What is the best way to achieve that? I am not looking for code specifically but trying to understand all options so I can do this in C#.

Suggestions are appreciated. Thank you



Solution 1:[1]

You can do any of the followings:

  • Write a SQL script which will read the data from the table and save those to the disk. Here is how that can be done
  • You can write a C# script which will connect to the Database, Read and store the data as a file to a disk

Use the Id of the table as part of the file name to make it unique if you are storing all the files to a single folder.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahatur