title: Azure Logic Apps internal server error 500
body: <p>Am trying to create a an azure function that is triggered in a Logic Apps, 
  The functions purpose is to web crawl certain web sites, take the desired information, compare that with a a SQL Server database in Azure, compare if we already have that information if not add it.</p>
  
  <p>My issue is that when ever i run it I get the Server 500 error, I assume its  accessing the database that cause. Help?</p>
  
  <pre><code>   public static async Task&lt;IActionResult&gt; Run(
              [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log
              )
          {
              log.LogInformation("C# HTTP trigger function processed a request.");
  
  
              string RequestBody = await new StreamReader(req.Body).ReadToEndAsync();
  
  
              {
                  return await CrawlBlog(0, RequestBody);
              }
  
          }
  
  
  
          private static async Task&lt;IActionResult&gt; CrawlBlog(int Picker, string req)
          {
  
              int BlogPicker = Picker;
  
              string TheResult = req;
              //Get the url we want to test
              var Url = "";
              if (BlogPicker == 0)
              {
                  Url = "*********";
              }
              else if (BlogPicker == 1)
              {
                  Url = "*********";
              }
              /*
              else if (BlogPicker == 2)
              {
                  Url = "https://azure.microsoft.com/en-in/blog/?utm_source=devglan";
              }
              */
              else
              {
                  TheResult = "False we got a wrong pick";
                  return (ActionResult)new OkObjectResult
                      ( new {TheResult });
                      }
  
              var httpClient = new HttpClient();
              var html =  await httpClient.GetStringAsync(Url);
              var htmlDocument = new HtmlDocument();
  
              htmlDocument.LoadHtml(html);
  
  
              //a list to add all availabel blogs we found
              var Blog = new List&lt;BlogStats&gt;();
  
              switch (BlogPicker)
              {
                  case 0:
                      {
                          var divs =
                          htmlDocument.DocumentNode.Descendants("div")
                              .Where(node =&gt; node.GetAttributeValue("class", "").Equals("home_blog_sec_text")).ToList();
  
  
  
                          foreach (var divo in divs)
                          {
                              var Blogo = new BlogStats
                              {
  
                                  Summary = divo.Descendants("p").FirstOrDefault().InnerText,
  
                                  Link = divo.Descendants("a").FirstOrDefault().ChildAttributes("href").FirstOrDefault().Value,
  
                                  Title = divo.Descendants("a").FirstOrDefault().InnerText
                              };
  
                              Blog.Add(Blogo);
  
  
                          }
  
                          break;
                      }
  
                  case 1:
                      {
                          var divs =
                          htmlDocument.DocumentNode.Descendants("div")
                              .Where(node =&gt; node.GetAttributeValue("class", "").Equals("post_header_title two_third last")).ToList();
  
                          foreach (var divo in divs)
                          {
                              //string TheSummary = "we goofed";
  
                              var ThePs = divo.Descendants("p").ToList();
  
  
                              var Blogo = new BlogStats
                              {
  
  
                                  Summary = ThePs[1].GetDirectInnerText(),
  
  
                                  Link = divo.Descendants("a").LastOrDefault().ChildAttributes("href").FirstOrDefault().Value,
  
                                  Title = divo.Descendants("a").FirstOrDefault().InnerText
  
                              };
  
                              Blog.Add(Blogo);
  
  
                          }
  
                          break;
                      }
  
  
              }
  
  
  
              TheResult = await SqlCheck(Blog[0].Title, Blog[0].Summary, Blog[0].Link); //error 500
  
  
              return (ActionResult)new OkObjectResult
              (
                  new
                  {
                      TheResult
                  }
                  );
  
          }
  
          public static async Task&lt;string&gt; SqlCheck(string Tit, string Sumy, string Lin)
          {
  
              SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
              builder.DataSource = "flygon.database.windows.net";
              builder.UserID = "*****";
              builder.Password = "********";
              builder.InitialCatalog = "torkoal";
  
              System.Data.DataSet ds = new System.Data.DataSet();
  
              SqlConnection connection = new SqlConnection(builder.ConnectionString);
  
              connection.Open();
  
  
  
              SqlCommand CheckCommand = new SqlCommand("SELECT * FROM TableBoto WHERE  Link = @id3 ", connection);
  
              CheckCommand.Parameters.AddWithValue("@id3", Lin);
  
              SqlDataAdapter dataAdapter = new SqlDataAdapter(CheckCommand);
  
  
  
              dataAdapter.Fill(ds);
  
              int i = ds.Tables[0].Rows.Count;
  
  
              if (i &gt; 0)
              {
  
  
                  return $" We got a Duplicates in title : {Tit}";
              }
  
  
  
              try
              {
  
                  {
  
  
  
                      string query = $"insert into TableBoto(Title,Summary,Link) values('{Tit}','{Sumy}','{Lin}');";
  
                      SqlCommand command = new SqlCommand(query, connection);
  
  
  
                      SqlDataReader reader = await command.ExecuteReaderAsync();
  
  
  
                      reader.Close();
                  }
              }
  
              catch (SqlException)
              {
                  // Console.WriteLine(e.ToString());
              }
  
  
              connection.Close();
  
  
  
              return $" Success Ign +{Tit} + Ign {Sumy}+ Ign {Lin} Ign Success SQL ";
  
          }
      }
  </code></pre>