Yogesh
Yogesh

Reputation: 3482

Implicit conversion from data type varchar to varbinary(max) is not allowed

CREATE PROCEDURE uspInsertImage
@PCImage varbinary(max)
As
Begin

INSERT INTO dbo.PCInfo PCImage) 
VALUES (@PCImage) 

End

When I Write

EXEC uspInsertPC 'D:\Desktop.jpg'

Showing Error

Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

Upvotes: 0

Views: 9389

Answers (1)

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

You are tried to save a string into a binary column that’s why you are getting this error

You should tell SQL server to use a different source provider by using OPENROWSET

you should do something the below:

INSERT INTO BLOBTest
    (BLOBName, BLOBData)
    SELECT 'First test file', 
        BulkColumn FROM OPENROWSET(
            Bulk 'C:\temp\nextup.jpg', SINGLE_BLOB) AS BLOB

For more info have a look at the below:

http://www.databasejournal.com/features/mssql/article.php/3724556/Storing-Images-and-BLOB-files-in-SQL-Server-Part-2.htm

Upvotes: 2

Related Questions