I am connecting time-triggered Azure Function with SQL Server using SQL client but I am not getting any data.
Here is my code:
local.settings.json
:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"DefaultConnection": "Data Source=; Initial Catalog=;User ID=;Password=;MultipleActiveResultSets=True;Persist Security Info=True;"
}
}
Function1.cs
:
public class Function1
{
[FunctionName("Function1")]
public static async Task Run([TimerTrigger("0 45 14 * * *")]TimerInfo myTimer, ILogger log)
{
var sqlConnection = Environment.GetEnvironmentVariable("DefaultConnection");
using (SqlConnection conn = new SqlConnection(sqlConnection))
{
conn.Open();
var text = "SELECT * from UserMaster where UserId=1234";
//This query has around 50 data in the database but still getting no data in it.
using (SqlCommand cmd = new SqlCommand(text, conn))
{
using (SqlDataReader reader = await cmd.ExecuteReaderAsync())
{
while (reader.Read())
{
log.LogInformation($"{reader.GetString(0)}{reader.GetString(1)} rows selected");
Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetString(1));
}
}
}
conn.Close();
}
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
I am not getting what is wrong with it. Please suggest
I think you can use
public override object this[string name] { get; }
instead. Here's my code and it worked well, you may compare it with yours.