Click here to Skip to main content
11,920,772 members (59,729 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET SQL Server
Hi to all. In my project i need to save user uploaded images into sql Server database.I thought to store those images directly into database by taking Image type column and i will retrieve them whenever i need to.But some of my friends are saying that this will result into performance issues as the app need to download those images directly from database.So,they are suggesting to save only the paths of images in database.but here my problem is what will be the situation if any image is not available in the stored path or missing by any chance?.I am totally confused in this scenario.So, guys please guide me according to this scenario where i can implement secured approach and i can avoid performance at the same time

Thanks in Advance
Posted 30-Jan-13 21:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Here you need to decide based on requirement.
Whether the total size of expected images would easlily be stored on database. Storing image in DB would obiously will increase load on DB.

Storing the path of image in database is better in case your database server degrades if saved in DB. Also storing image in file system will provide much more flexibility and scalability.

Regarding securty if save images in file system, I think it will be stored on some secured server and these will not be accessible to all. So if your server is secured enough then I don't see any security issue.

So decide based on your size of the images and database server capability.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

        using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connectionString))
            // OPEN CONNECTION
            // READ IMAGE BYTES
            byte[] bt = System.IO.File.ReadAllBytes(@"D:\image.jpg");
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "your_storedprocedure_name";
            // ASSIGN IMAGE TO StoredProcedure PARAMETER
            System.Data.SqlClient.SqlParameter param = new System.Data.SqlClient.SqlParameter("@imgdata", bt);
            // EXECUTE StoredProcedure TO SAVE IMAGE
            // CLOSE CONNECTION
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

What your friends suggesting is right. saving images in database will decrease in performance and hence you will save path or imagename only in database.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 548
1 Dave Kreskowiak 245
2 phil.o 170
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,815
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web02 | 2.8.151120.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100