From b341c59507774000c3e1f6538b0c027f2045c2ba Mon Sep 17 00:00:00 2001 From: Jason Divis Date: Fri, 28 Mar 2025 10:47:48 -0500 Subject: [PATCH] Adding a call to get users from a table --- .../azure-functions/Function1.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/child-sponsor-demo/azure-functions/Function1.cs b/child-sponsor-demo/azure-functions/Function1.cs index dc89b8b..10a9e9c 100644 --- a/child-sponsor-demo/azure-functions/Function1.cs +++ b/child-sponsor-demo/azure-functions/Function1.cs @@ -10,4 +10,32 @@ public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogge { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); } + + public static void GetUser(string userInput, ILogger log) + { + string connectionString = "Server=tcp:wedkjnwerfihnj.database.windows.net,1433;Initial Catalog=wedkjnwerfihnj;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=\"Active Directory Default\";"; + string query = $"SELECT * FROM Users WHERE Username = '{userInput}'"; + + try + { + using (var connection = new System.Data.SqlClient.SqlConnection(connectionString)) + { + connection.Open(); + using (var command = new System.Data.SqlClient.SqlCommand(query, connection)) + { + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + log.LogInformation($"User: {reader["Username"]}"); + } + } + } + } + } + catch (Exception ex) + { + log.LogError($"An error occurred: {ex.Message}"); + } + } } \ No newline at end of file