?
Solved

Uploading image file to FILESTREAM column in SQL Server

Posted on 2014-01-03
2
Medium Priority
?
766 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

765 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