Insert an image into an sql2008 table

Discussion in 'Databases' started by mmorell, Oct 6, 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'm trying to put some images into a table like this:

    UPDATE dbp.productos
    SET foto =
    (SELECT * FROM
    OPENROWSET(BULK N'C:\Documents and Settings\mmorell\My Documents\Visual Studio 2008\Projects\adp\adp\Resources\Images\manzana.JPG', SINGLE_BLOB) AS ORS)
    WHERE prodid = '1' )

    but getting the error:
    Msg 4834, Level 16, State 1, Line 4
    You do not have permission to use the bulk load statement.

    In microsoft SQL Server managment I cannot add the bulk role to my user.
    How can I update the images in a table then? Please advise :)
     
  2. mjp

    mjp

    You could write a script to upload them one at a time or in smaller groups. You will find bulk load or insert is not allowed at most shared hosts for performance reasons.

    Though some would question the practice of adding images to a database in the first place. Especially at a shared host where you have a database size quota to consider. It's usually more efficient to add an image reference (e.g., a path and file name), and store the images in a directory.
     
  3. I largely agree with mjp so far as you might consider questioning the requirement for storing images in the db. I don't completely dismiss this idea as bad practice because there are some specialized applications where it is a good design decision but I'd say that in the majority of cases it will be best to avoid storing images in the database.
     
  4. I think you'll find better success using .NET to get a filestream, capture all the binary bits and store the image in a varbinary(max) field.
     
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