【问题标题】:Connection to Azure Blob and delete file if exists连接到 Azure Blob 并删除文件(如果存在)
【发布时间】:2018-09-06 07:42:33
【问题描述】:

我有一个要求,我需要使用 SSIS 脚本任务 c# 连接到 Azure 容器并检查文件名 (abc.csv)。如果文件存在,则将变量更新为 1 并删除该文件。

以下是我在尝试了几个网站后设法编写的代码:-

#region Namespaces
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Threading.Tasks;
#endregion

      public void Main()
            {
                CloudStorageAccount storageAccount = new CloudStorageAccount(
       new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
       "Account_Name","XXX0sCXXQsBXXXxMnXXXXXXNXXXPCjPQ=="), true);

                // Create a blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                // Get a reference to a container named "mycontainer."
                CloudBlobContainer container = blobClient.GetContainerReference("test");

                if (container.GetBlockBlobReference("abc.csv").Exists())
                {
                    Dts.Variables["User::FileExistsFlg"].Value = "1";
                }

上述脚本因调用错误而失败。而且我不确定一旦变量更新为 1 后如何删除文件。

【问题讨论】:

  • 哪里失败了?
  • 我收到错误:- 调用目标抛出异常。
  • 也许你需要寻找你的代码的innerException。使用 F12 逐步调试。

标签: c# visual-studio azure ssis azure-blob-storage


【解决方案1】:

正如我所测试的,在Dts.Variables["User::FileExistsFlg"].Value = "1"; 之前它总是运行良好。

所以我建议您检查一下您的 Script Task 是 ReadOnlyVariables 还是 ReadWriteVariables。这里有人从blob加载CSV,你可以参考it

之后,您可以尝试debug Script Task。

注意: 当您在 64 位模式下运行包时,您无法调试脚本任务。您必须执行包才能调试到您的脚本任务。如果只执行单个任务,脚本任务代码中的断点将被忽略。

如果无法调试脚本任务,可以尝试implement log in your packages

Integration Services 日志提供程序可以将日志条目写入文本文件、SQL Server Profiler、SQL Server、Windows 事件日志或 XML 文件。

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 2021-12-12
    • 2021-07-11
    • 2017-09-17
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    相关资源
    最近更新 更多