I make reference to the below solution that I found on Stack. It's pretty close to what I am attempting to do but after a week of trying various options I am no closer.
I am attempting to write an Azure Function that will extract all the data from Azure Database and output the results to Blob Storage..
Below is my attempt. After exhausting all others, admittedly I'm not great at C# so it's probably my shortcoming. Any help will be greatly appreciated.
Here is the Azure Function:
#r "System.Configuration"
#r "System.Data"
using System.Configuration;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Text;
using System.IO;
public static void Run(
[TimerTrigger("0 */30 * * * *")] TimerInfo myTimer,
[Blob("mycontainer/myblob.txt", FileAccess.Write)] out string OutputBlob,
TraceWriter log)
{
SqlDataReader rdr = null;
var str = ConfigurationManager.ConnectionStrings["sqldb_connection"].ConnectionString;
using (var conn = new SqlConnection(str))
{
conn.Open();
// Query Text
var text = "SELECT FirstName, LastName FROM Kpi";
using (var cmd = new SqlCommand(text, conn))
{
// Execute the command
rdr = cmd.ExecuteReader();
var csv = new StringBuilder();
while (rdr.Read())
{
// get the results of each column
string FirstName = (string)rdr["FirstName"];
string LastName = (string)rdr["LastName"];
// create a string
var newLine = string.Format("{0},{1}", FirstName, LastName);
csv.AppendLine(newLine);
}
// How do I get the results to the outputBlob ??
File.WriteAllText(outputBlob, csv.ToString());
}
}
}
Here is the error:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.TimerTriggerCSharp1 ---> Microsoft.CodeAnalysis.Scripting.CompilationErrorException : Script compilation failed. at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 340 at async