Solved

Uploading image file to FILESTREAM column in SQL Server

Posted on 2014-01-03
2
745 Views
Last Modified: 2014-01-03
When trying to upload an image file to a Filestream column in SQL Server 2008 using the code below, it fails because the GUID column (UI) is not auto-generating a value - at least that's my reading of the error message, which is: "Cannot insert the value NULL into column 'UI'. Insert fails".

INSERT INTO T_Photos (Filename, Location, Photo)
SELECT 'myImage.JPG', 'London', Photo.*
FROM OPENROWSET (BULK 'C:\myPath\myImage.JPG', SINGLE_BLOB) Photo
0
Comment
Question by:TimHudspith
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39753941
Your column does not allow NULL, so provide a value:

INSERT INTO T_Photos (UI, Filename, Location, Photo)
SELECT newid(), 'myImage.JPG', 'London', Photo.*
FROM OPENROWSET (BULK 'C:\myPath\myImage.JPG', SINGLE_BLOB) Photo
0
 
LVL 26

Expert Comment

by:tigin44
ID: 39753950
try

INSERT INTO T_Photos (UI,Filename, Location, Photo)
SELECT NEWID(), 'myImage.JPG', 'London', Photo.*
FROM OPENROWSET (BULK 'C:\myPath\myImage.JPG', SINGLE_BLOB) Photo
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now