1
votes

When using an SSIS Script task to talk to Azure Blob storage, the following code does not run, it builds ok and will run in a console app! Can anyone provide any insight into what's going wrong, as there are no error messages other than this one within SSIS or the event logs.

Namespaces:

using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Linq;

Code:

string AccountName = Dts.Variables["User::AccountName"].Value.ToString();
        string AccountKey = Dts.Variables["User::AccountKey"].Value.ToString();
        try
        {
            StorageCredentials storageCredentials = new StorageCredentials(AccountName, AccountKey);
            CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, useHttps: true);
            CloudBlobClient BlobClient = cloudStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer Container = BlobClient.GetContainerReference("deltapocstorage");
            CloudBlobDirectory blobDirectory = Container.GetDirectoryReference("instance1/");

            CloudBlockBlob latestBlob = blobDirectory.ListBlobs()
                                          .OfType<CloudBlockBlob>()
                                          .OrderByDescending(m => m.Properties.LastModified)
                                          .ToList()
                                          .FirstOrDefault();

            DateTimeOffset lastModifiedDate = new DateTimeOffset();

            if (latestBlob != null)
            {
                lastModifiedDate = latestBlob.Properties.LastModified.GetValueOrDefault();
                Dts.Variables["User::MostRecentRecord"].Value = lastModifiedDate.AddMilliseconds(1).ToString("dd/MM/yyyy HH:mm:ss.fff");
            }

            Dts.TaskResult = (int)ScriptResults.Success;
        }
        catch
        {
            Dts.TaskResult = (int)ScriptResults.Failure;
        }

Any ideas would be appreciated,

regards, Anthony

1

1 Answers

1
votes

It looks like the issue is associated with the Microsoft.WindowsAzure.Storage.dll assembly, not being located in the Global Assembly Cache (GAC). Adding the assembly using

gacutil.exe /i "C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Microsoft.WindowsAzure.Storage.dll"

and the script worked. Once I worked this out a better way to ensure the assembly is loaded is to follow this post from David Browne How to load an assembly in an SSIS script task