Help with SQL and images

Discussion in 'Databases' started by aaron, Jun 30, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I used asp:FileUpload control on my aspx page to allow my user to upload images. Now what I need to do is save the path to that image in SQL. How do I go about doing this? I have looked around and have not really found what I need.

    Any help would be great.

    Thank you
     
  2. Hi Aaron,

    Data access in .NET is a fairly large area but if you're completely new to it, I would recommend you start your reading here: http://msdn.microsoft.com/en-us/library/hdb58b2f(VS.80).aspx

    In the simplest of terms to answer your question quickly, you can achieve your goal with an ADO.NET SqlCommand class instance. http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand(VS.80).aspx

    Whilst this will certainly work and will functionally enable your code quickly, there are some important things to keep in mind which are discussed in detail in the ADO.NET security best practice articles:

    Notes:
    • The example included in the SqlCommand documentation page demonstrates a SELECT statement but it could equally be an INSERT or UPDATE.
    • LINQ to SQL is another method of achieving this type of functionality
    • Hardcoding parameters is not recommended in any db access layer. Parameterized stored procedures is preferred to help prevent SQL injection attack.
    • Hardcoding SQL is not recommended in any db access layer due to inflexibility / maintainability issues. Using stored procedures in the db will provide better security / performance and also promotes separation of tiers.

    Finally if you're looking for a good ASP.NET book, this is the best one I've read:
    http://www.amazon.com/Pro-ASP-NET-3...=sr_1_2?ie=UTF8&s=books&qid=1246433640&sr=8-2

    I read the 2nd edition and it's now up to #3 but the amazon reader reviews are very good for all editions.

    Hope that helps,
    Joe
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    IMHO, i don't like storing images in SQL database. DB is really not designed for storing BLOB and you don't gain much by storing the image in the DB. It will actually be slower than compare to storing it in filesystem.

    I rather store the image in the file system and store the link to reference the image.
     
  4. Yes generally I agree that the filesystem should be used for persisting files and a database is used to describe the location of the file in the filesystem - as I understand it, this is what the OP is attempting to do.

    That said there are some specific applications where storing images in the db is very useful or even functionally critical e.g. image and content manipulation systems where auditing, versioning and searching on the content is a core requirement...but most applications will get by perfectly well and achieve higher performance with files on disk rather than in the db.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page