简体   繁体   English

如何使用 SSIS 将文档(文本、csv、excel)或 BLOB 文件加载到 varbinary(MAX) 数据库列中

[英]How to load a document(text,csv,excel) or BLOB file into a varbinary(MAX) database column using SSIS

I look for any resources that I can, but I only see examples of loading images into varbinary(max) columns in SQL Server.我尽可能地寻找任何资源,但我只看到将图像加载到 SQL Server 中varbinary(max)列的示例。 I want to convert the actual documents into varbinary format, and load them into a database column.我想将实际文档转换为varbinary格式,并将它们加载到数据库列中。

I will worry about converting them later.我会担心以后转换它们。 I know you are going to say "Why would you do that when you could just store the directory of the file and retrieve the file from the file location on the server?"我知道你会说“当你可以只存储文件的目录并从服务器上的文件位置检索文件时,你为什么要这样做?” It's because we are creating a framework for sending notifications, and the BLOB files that we are loading are going to be the documents - or attachments of any type.这是因为我们正在创建一个用于发送通知的框架,我们正在加载的 BLOB 文件将是文档 - 或任何类型的附件。 It's just the way my boss wants it done.这正是我老板想要的方式。

CREATE TABLE [dbo].[AEI_Notification_Artifacts]
(
    [artifact_id] [BIGINT] IDENTITY(1,1) NOT NULL,
    [notification_id] [BIGINT] NOT NULL,
    [artifact] [VARBINARY](MAX) NULL,

    CONSTRAINT [PK_AEI_Notification_Artifacts] 
        PRIMARY KEY CLUSTERED ([artifact_id] ASC)
                    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
                          IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                          ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

I am trying to load files and convert them in SSIS via a flat file and import column task... But the resources that I found only work with images.我正在尝试通过平面文件和导入列任务加载文件并在 SSIS 中转换它们......但我发现的资源仅适用于图像。 I am thinking I am going to need to create a manual complex script that will convert the data then stream it.我想我需要创建一个手动复杂脚本来转换数据然后流式传输它。

We can handle this without needing to utilize a script task in SSIS.我们无需使用 SSIS 中的脚本任务即可处理此问题。

Here is a small example.这是一个小例子。 In your case you can replace the Source component with your FlatFile source.在您的情况下,您可以将 Source 组件替换为您的 FlatFile 源。 The FlatFile source should output a column that is the filepath (example: C:\\support\\yourfile.bin ) to your file(s) that you wish to import. FlatFile 源应输出一列,该列是您希望导入的文件的文件路径(例如: C:\\support\\yourfile.bin )。

基本数据流示例

Next, we will configure the Import Column component:接下来,我们将配置导入列组件:

First let's select the column to use as the input, this should be your file path column from above.首先让我们选择要用作输入的列,这应该是上面的文件路径列。 示例数据流示例

Next we need to add the column that we are going to import.接下来我们需要添加我们要导入的列。 First go select Import Column Output/Output Columns and then press the Add Column button.首先选择导入列输出/输出列,然后按Add Column按钮。 Next set the DataType to [DT_IMAGE] (This will translate to varbinary(MAX) when writing to the destination).接下来将DataType设置为[DT_IMAGE] (这将在写入目标时转换为varbinary(MAX) )。 Finally make note of the LineageID.最后记下 LineageID。 配置添加的导入列设置

Now back to the Import Column Input\\Input Columns \\ FilePath.现在回到导入列 Input\\Input Columns \\ FilePath。 Select that column and then under Customer Properties set FileDataColumnID to the LineageID that we noted before.选择该列,然后在Customer PropertiesFileDataColumnID设置为我们之前提到的 LineageID。 将 LineageID 分配给输入列

Now you should be all set to drop your data into the your destination of choice.现在您应该准备好将数据放入您选择的目的地。

[Edit: typos] [编辑:错别字]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从VARBINARY(MAX)列打印Word文档 - Print a Word document from VARBINARY(MAX) column 使用 Angularjs 中的 Web API 将 pdf 文件作为 varbinary(max) 插入到数据库中? - Insert pdf file as varbinary(max) into the database using web API in Angularjs? 如何将Excel文件插入到具有varbinary类型的列到SQL表中? - How to insert an Excel file to a column with varbinary type into an SQL table? 如何在INSERT上将BLOB流式传输到VARBINARY(MAX) - How can I stream a BLOB to VARBINARY(MAX) on INSERT 如何将字节 [] 上传到 varbinary(max) 从 blob 到 sql - how to upload bytes[] to varbinary(max) from blob to sql 如何将图像存储到varbinary(max)列? - How to store images to a varbinary(max) column? 如何在Excel Server 2008的varbinary(max)列中插入/检索Excel文件? - How do I insert/retrieve Excel files to varbinary(max) column in SQL Server 2008? 从excel导入超过255个字符到sql server(上一个问题 - 如何使用ssis将文本限定的CSV动态加载到sql server) - Import more than 255 Characters from excel to sql server (previous question - how to load text qualifed CSV dynamically to sql server using ssis) 在varbinary列中顺序写入blob - Write blob sequentially in varbinary column C#:如何使用 varbinary(Max) 将图像上传到 SQL 服务器数据库 - C# : how to upload image to a SQL Server database using varbinary(Max)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM