use*_*182 6 ssis image azure-storage
是否可以从SQL SSIS包上传图像到Windows azure blob存储?SSIS将从我的一个内部部署SQL Server(表)上读取新图像(每天),并将图像上传到blob存储.
bil*_*nkc 13
这是多么有趣的问题!我要拼凑很多我从未尝试过的作品.
我首先在HOW TO:Blob Storage上基于精细手册构建了一个简单的控制台应用程序.知道我有工作代码允许我适应SSIS.
我在包级别创建了3个SSIS变量.AccountName,AccountKey和ContainerName.它们都是数据类型String.这些提供凭据+我上传的数据所在的文件夹.

数据流的一般外观相当简单.脚本组件的数据源,将充当目标.您将需要两列:一列为blob提供唯一名称,另一列为二进制位.
我的来源是一个简单的表.它有国家名称和他们的国旗(存储为varbinary(max)),如果你愿意,你可以从中央情报局世界手册中获取.
目的地将是一些C#.添加Destination类型的脚本组件.
在"脚本"选项卡上,我列出了3个ReadOnly变量 User::AccountKey,User::AccountName,User::ContainerName
在"输入列"选项卡上,我选择CountryName和FlagImage.
脚本本身如下.如"操作方法"中所述,您需要先添加对Microsoft.WindowsAzure.Storage程序集的引用,然后才能访问其中的最后3个程序集.
using System;
using System.Data;
using System.IO;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
// Must add reference to Microsoft.WindowsAzure.Storage for this to work
// http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
/// <summary>
/// Watch me load data to Azure from SSIS
/// </summary>
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
/// <summary>
/// The storage account used
/// </summary>
private CloudStorageAccount storageAccount;
/// <summary>
/// An entity to work with the Blobs
/// </summary>
private CloudBlobClient blobClient;
/// <summary>
/// Blobs live in containers
/// </summary>
private CloudBlobContainer container;
/// <summary>
/// blockBlob instead of a pageBlob
/// </summary>
private CloudBlockBlob blockBlob;
/// <summary>
/// This method is called once, before rows begin to be processed in the data flow.
///
/// You can remove this method if you don't need to do anything here.
/// </summary>
public override void PreExecute()
{
base.PreExecute();
string cs = string.Empty;
string csTemplate = string.Empty;
string accountName = string.Empty;
string accountKey = string.Empty;
string containerName = string.Empty;
accountName = Variables.AccountName;
accountKey = Variables.AccountKey;
containerName = Variables.ContainerName;
csTemplate = "DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}";
cs = string.Format(csTemplate, accountName, accountKey);
this.storageAccount = CloudStorageAccount.Parse(cs);
this.blobClient = this.storageAccount.CreateCloudBlobClient();
this.container = this.blobClient.GetContainerReference(containerName);
this.container.CreateIfNotExists();
this.container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
/// <summary>
/// For each row passing through, upload to Azure
/// </summary>
/// <param name="Row">The row that is currently passing through the component</param>
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string blobName = string.Empty;
using (MemoryStream memStream = new MemoryStream(Row.FlagImage.GetBlobData(0, (int)Row.FlagImage.Length)))
{
this.blockBlob = this.container.GetBlockBlobReference(Row.CountryName);
this.blockBlob.UploadFromStream(memStream);
}
}
}
Run Code Online (Sandbox Code Playgroud)
您希望在SSIS中使用的程序集必须位于GAC中.除非签署,否则大会不能进入GAC.幸运的是,Azure程序集是从Visual Studio命令提示符,类型gacutil -if "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.1\ref\Microsoft.WindowsAzure.Storage.dll"或等效于该程序集的版本所在的位置进行签名的
作为证据,这里是Azure Storage Explorer的一个镜头

| 归档时间: |
|
| 查看次数: |
3396 次 |
| 最近记录: |