Azure function to connect to both blob and sql storage

点点圈 提交于 2019-12-06 16:39:58

So, you need a function with

Here is my sketch for your function:

[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";
        }
    }
}

Your question is a bit open-ended, so feel free to update it with more details about your struggles.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!