连接到 blob 和 sql 存储的 Azure 函数

Azure function to connect to both blob and sql storage

我认为这是 Azure 功能的完美介绍测试用例。

我们在 Azure 中有一个 SQL 商店(SQL 数据库)。

使用 C#、VS 2017,更新了 Azure 工作流项目。

我们还有一个 Blob 存储。 每天晚上我都需要一个进程去 SQL 数据库,根据条件收集一组记录,然后处理它们生成一个文件,该文件将存储在 blob 存储中。

我似乎无法克服完成这些任务中的任何一个的困难。所有教程似乎都是最基本的类型。

我在 VS 2017 中创建了一个函数,但第一步只是连接到 SQL 数据库。

我去添加新项目:ADO.NET 实体数据模型,它的行为就像它创建了正确的模型但没有数据上下文?

因此,我决定尝试下一步——创建 blob 并仅使用硬编码的样本数据。再次......找不到关于如何做到这一点的好指南。

我在 local.setting.json 文件中有一个 "AzureWebJobsStorage" 设置。

我下面有一个定时器功能:

 public static class Function1
{
    [FunctionName("Function1")]
    public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");



    }

只是指出了正确的方向,我会继续努力...

所以,你需要一个函数

这是我的函数草图:

[FunctionName("Function1")]
public static void Run(
    [TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, 
    [Blob("mycontainer/myblob.txt", FileAccess.Write)] out string outputBlob,
    TraceWriter log)
{
    var str = ConfigurationManager.ConnectionStrings["sqldb_connection"].ConnectionString;
    using (var conn = new SqlConnection(str))
    {
        conn.Open();
        var text = "SELECT count(*) FROM MyData";

        using (var cmd = new SqlCommand(text, conn))
        {
            // Execute the command and log the # rows affected.
            var rows = cmd.ExecuteScalar();
            outputBlob = $"{rows} rows found";
        }
    }
}

你的问题有点开放性,所以请随时用更多关于你的挣扎的细节来更新它。