Storing binary data into SQL Server
In this recipe, we will store some binary data, including some images, a PDF, and a Word document, into SQL Server.
Getting ready
Let's create a sample table we can use for this recipe. Run the following in SQL Server Management Studio to create a table called SampleBLOB that has a BLOB, or VARBINARY(MAX), field:
USE SampleDB
GO
IF OBJECT_ID('SampleBLOB') IS NOT NULL
DROP TABLE SampleBLOB
GO
CREATE TABLE SampleBLOB
(
ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
FileName VARCHAR(200) ,
InsertedDate DATETIME DEFAULT GETDATE() ,
InsertedBy VARCHAR(100) DEFAULT SUSER_SNAME() ,
BLOBStuff VARBINARY(MAX) ,
FileExtension VARCHAR(50)
)Create a directory called C:\BLOB Files\ and copy the sample BLOB files that come with the book scripts, or use your own directory and BLOB files.
How to do it...
These are the steps to save binary data into SQL Server:
- Open the PowerShell console application by going to...