Search code examples
c#databaseimageimage-processingvarbinarymax

C# : Saving an Image into DB


Can someone give me some advice on how to save an image file into DB in C#? I will be saving a lot of images so what's the best way to reduce the space it will be needing? I'm currently using varbinary(max) field in DB.

Thanks!


Solution

  • If you MUST store the actual file in SQL then make sure you put some restrictions around the size of the image and make sure you properly plan the database sizing - how many images and of what size are you expecting?

    If you must store it in SQL my preferences is to automatically have it sitting in its own SQL database. This way any performance issues I run into with these images is not affecting the rest of my database.

    NOW, if you do not have to store the images in a SQL database then I think this is just calling out to be done with Azure Blob Storage. Go take a look at it - it will give you what you want in a very efficient system.

    If you cannot use Azure then you should put together a class that will handle reading/writing/lookup of images to a file system. Saving to the file system (done properly) will work much better than saving to SQL.