0

We want to upload pdf files into a SQL Server table.

Let's assume the size is about 256K.

This is the table DDL:

CREATE TABLE [dbo].[tblFiles]
( 
    [id] [int] IDENTITY(1,1) NOT NULL,  
    [Name] [varchar](50) NOT NULL,  
    [ContentType] [nvarchar](200) NOT NULL,  
    [Data] [varbinary](max) NOT NULL  
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 

We want to call these files from an SSAS Tabular cube (outside the scope of this question for now), so we are working on a POC.

I don't need to use code to store the file in the database. We just need to prove the POC would work, so how do I upload the file directly into the table?

I know with C# for example, binary reader is used to parse the content and whatnot, but uploading the file directly, how do I even get this info? Do I turn the pdf file into a zip file or something?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Cataster
  • 3,081
  • 5
  • 32
  • 79
  • Does this answer your question? https://stackoverflow.com/questions/3053564/upload-a-file-to-a-varbinary-with-sql-management-studio – Nikita Chayka Apr 26 '21 at 16:36
  • @NikitaChayka i think so! the only problem i see is i dont have access to the sql server, only the DBA does, so i can only connect to the DB engine through SSMS. but bulking loading the file, i see in the T-SQL there is a location `C:\...` which i think will be a problem since that location for us is probably the sql server location, not my local location – Cataster Apr 26 '21 at 16:38
  • It is SQL Server location indeed. I believe it is the only valid way to do it from SSMS, otherwise write the program that will do it, it should not be hard, 20 lines of code, simple Console application will do it – Nikita Chayka Apr 26 '21 at 16:45
  • @NikitaChayka looks like we'll just utilize powerbi directly to use the PDF's from Sharepoint directly i think. Good to know about this though for future reference – Cataster Apr 26 '21 at 19:13
  • Can `bcp` not do this? – Charlieface Apr 27 '21 at 08:35

0 Answers0