0

i am working on a C# project and need help as to how to insert data into the database from the queue trigger, i have a console app that inserts data to the queue on azure and then it gets triggered by the function app, what i don't know how is to add that to a database

so i need to link this to the database and make sure it runs on azure im on the azure but struggling to get it to trigger there as well

public class Function1
  {
      [FunctionName("Function1")]
      public void Run([QueueTrigger("part2", Connection = "st10090552connectionstring")]string myQueueItem, ILogger log)
      {
          
          Console.WriteLine($" messages in queue :" +
              $"" +
              $": {myQueueItem}");
          Console.WriteLine($"function has pulled the data from the queue");
      }
      
  }
public static void InsertMessage(string Name)
        {
            
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            QueueClient Client = new QueueClient(connectionString, Name);

            // Create the queue if it doesn't already exist
            Client.CreateIfNotExists();
            DateTime date = new DateTime(2021, 12, 31);

            double ID;
            double ID2;
            double barcode;
            string VACCINATIONCENTER;
            string VACCINATIONDATE;
            double VACCINATIONSERIALNUMBER;
            string VACCINATIONCENTER2;
            string VACCINATIONDATE2;



            Console.WriteLine("ENTER YOUR ID");
            string data = Console.ReadLine();
            ID = double.Parse(data);
            Console.WriteLine("ENTER THE VACCINATION CENTER");
            VACCINATIONCENTER = Console.ReadLine();
            Console.WriteLine("ENTER THE VACCINATION DATE");
            VACCINATIONDATE = Console.ReadLine();
            Console.WriteLine("ENTER YOUR SERIAL NUMBER");
            string data1= Console.ReadLine();
           VACCINATIONSERIALNUMBER = double.Parse(data);



            Console.WriteLine("ENTER YOUR BARCODE FOR VACCINES");
            string data2 = Console.ReadLine();
            barcode = double.Parse(data);
            Console.WriteLine("ENTER THE VACCINATION DATE");
            VACCINATIONCENTER2 = Console.ReadLine();
            Console.WriteLine("ENTER THE VACCINATION CENTER");
            VACCINATIONDATE2 = Console.ReadLine();
            Console.WriteLine("ENTER YOUR ID");
            string data3 = Console.ReadLine();
            ID2  = double.Parse(data);

            var message1  = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(ID.ToString() + ":"+ VACCINATIONCENTER +":" + VACCINATIONDATE +":"+VACCINATIONSERIALNUMBER.ToString()));
            var message2 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(barcode.ToString() + ":" + VACCINATIONCENTER2 + ":" + VACCINATIONDATE2 + ":" + ID2.ToString()));

            Client.SendMessage(message1); ;
                
                Console.WriteLine($"messages saved successfully  ");
            
           
           

            Console.ReadKey();
        }
       
Thom A
  • 88,727
  • 11
  • 45
  • 75
OMO
  • 3
  • 6
  • What kind of database are you using? What have you tried so far? Where are you stuck? – Markus Meyer Oct 07 '22 at 05:45
  • @MarkusMeyer it needs to go on azure sql and i have tried to find documentation or methods to do this with no luck , i am stuck on how to get it into the azure sql database – OMO Oct 07 '22 at 05:49
  • 1
    Not sure on what you are not able to find documentation on. You can instantiate a database connection and add the necessary data into DB using plain ADO code or frameworks like Entity Framework – WisdomSeeker Oct 07 '22 at 05:54
  • @WisdomSeeker from a queue trigger? i should note that i haven't done this before – OMO Oct 07 '22 at 06:02
  • Can you please share your current code? – Markus Meyer Oct 07 '22 at 06:06
  • 1
    @MarkusMeyer i added it to the main question – OMO Oct 07 '22 at 06:13
  • 1
    Can you please check this link https://learn.microsoft.com/en-us/azure/azure-functions/functions-scenario-database-table-cleanup – WisdomSeeker Oct 07 '22 at 06:32

0 Answers0