c# - 将列表 <string> 存储到 SQL 数据库表?

标签 c# mysql azure azure-blob-storage

我想在 Microsoft Azure 中查找存储帐户,列出特定容器(在存储帐户中)中的 blob,然后将列出的 blob 名称存储到数据库表中。任何人请建议一个 C# 代码来将 blob 名称列表存储到数据库表中。

namespace ListStorageAccntFiles
{
    class Program
    {            
        static void Main(string[] args)
        {
            Console.Clear();

            //Code to list the blobnames in Console

            CloudStorageAccount StorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            var BlobClient = StorageAccount.CreateCloudBlobClient();
            var Container = BlobClient.GetContainerReference("samples-workitems");
            var list = Container.ListBlobs();

            List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
            blobNames.ForEach(Console.WriteLine);

            //Code to store blobnames under the column header "name" in a database table
         }
     }
}

最佳答案

with the scenario!!!! program that can look at storage account and process all new & modified files and take an action if there is any new ones

我认为,我建议使用WebJobs SDK的BlobTrigger来达到你的目的。下面是我的代码示例,以便你更好地理解它:

WebJob 类

public class Functions
{
    //This function will get triggered/executed when a blob is created or updated on an Azure Blob container called trigger-blob-input.
    public static void TriggerAzureBlob([BlobTrigger("trigger-blob-input/{name}")] ICloudBlob blob)
    {
        Console.WriteLine("Blob name:" + blob.Name);
        //do something with the created/updated blob
    }
}

当按如下方式创建/更新 blob 时:

1

您可以通过 BlobTrigger 检测 blob 并获得以下输出:

2

更多详细信息,您可以引用以下教程:

how to create a WebJob and deploy it to Azure

how to trigger a function when a blob is created or updated

此外,WebJobs SDK 还会扫描日志文件以监视新的或更改的 blob。此过程不是读取时的,因此在创建/更新 blob 后的短时间内或较长时间内可能不会触发函数。

如果 blob 触发器的限制不满足您的应用程序,您可以在创建/更新 blob 时创建队列消息,然后使用 QueueTrigger而不是处理 Blob 的函数上的 BlobTrigger。

关于c# - 将列表 <string> 存储到 SQL 数据库表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39122699/

相关文章:

c# - 如何在 C# 中从 CultureInfo 获取 "UK"

c# - 在 ASP.Net vNext 站点中,为什么在启动时会出现与迁移相关的异常?

php - 尝试获取锁时发现哪个查询导致死锁;尝试重启交易

azure - 如何使用 Terraform 'error dial tcp 127.0.0.1:80: connect: connection refused' 修复 Azure Kubernetes 服务?

azure - 无法在azure上创建sql服务器

c# - 使用 Entity Framework 时尝试读取或写入 protected 内存

c# - 如何将生成的网格添加到另一个生成的 child ?

c# - 在 .NET 中注册文件类型和自定义文档图标

mysql - 错误 1045 (28000) : Access denied for user 'root' @'localhost' (using password: YES)

php - 为什么我的查询没有定义该值?