Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NETSQLServer
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 - 20:23


4 solutions

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.
  Permalink  
// CREATE DATABASE CONNECTION
        using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connectionString))
        {
            // OPEN CONNECTION
            con.Open();
 
            // READ IMAGE BYTES
            byte[] bt = System.IO.File.ReadAllBytes(@"D:\image.jpg");
 
            // CREATE SQLCOMMAND AND SPECIFY PROPERTIES
            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);
            cmd.Parameters.Add(param);
 
            // EXECUTE StoredProcedure TO SAVE IMAGE
            cmd.ExecuteNonQuery();
 
            // CLOSE CONNECTION
            con.Close();
        }
  Permalink  
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.
 
Thanks
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 468
1 Mahesh Bailwal 413
2 Aarti Meswania 195
3 Maciej Los 180
4 CPallini 150
0 Sergey Alexandrovich Kryukov 9,607
1 OriginalGriff 7,214
2 CPallini 3,943
3 Rohan Leuva 3,261
4 Maciej Los 2,758


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid