Hi @wavemaster
I have gone through our official documentation on this matter and didn't run into any issues using the System.Data.SqlClient
with version 4.5.1
.
Below is a working sample where I pull a list of characters (strings) from an Azure SQL DB in an HttpTriggered Function App:
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace murnunapp
{
public static class HttpTrigger
{
[FunctionName("HttpTrigger")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var connStr = Environment.GetEnvironmentVariable("SQLConnectionString");
List<Character> characters = new List<Character>();
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
var text = "SELECT * FROM [users]";
using (SqlCommand cmd = new SqlCommand(text, conn))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
characters.Add(new Character(){ Firstname = (string) reader.GetValue(1), Lastname = (string) reader.GetValue(2) });
}
}
}
}
dynamic data = JsonConvert.SerializeObject(characters);
return new OkObjectResult(data);
}
}
public class Character
{
public string Firstname { get; set; }
public string Lastname { get; set; }
}
}
Which returns a JSON response of the following:
I hope this is useful, and the sample code above can be leveraged to resolve the issue that you're encountering. Just let me know if you had any further questions.