Click here to Skip to main content
Rate this: bad
good
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 20:23pm
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

// 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  
Rate this: bad
good
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.
 
Thanks
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 370
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 130
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
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