title: An error occurred Send Events: Azure Function Output Adapter failed to write events Azure Function as Stream Analytics Job Output
body: <p>I have an Azure IoT Dev Kit MXChip and I am sending the sensor data to the IoT Hub. I have also set up the Stream Analytics Job with Input as IoT Hub and Output as SQL Server and Azure Function. The output is getting written to the SQL Database, so I am confirming that the Query is correct. </p>
  
  <p>When I check my stream analytics job log, I am seeing some error as below. </p>
  
  <pre><code>{
      "channels": "Operation",
      "correlationId": "4a9c9b61-631a-4f4f-a403-c2869b2af66c",
      "description": "",
      "eventDataId": "97250faf-fa47-4e78-9981-8429f293bab9",
      "eventName": {
          "value": "streamingNode0",
          "localizedValue": "streamingNode0"
      },
      "category": {
          "value": "Administrative",
          "localizedValue": "Administrative"
      },
      "eventTimestamp": "2018-12-18T15:54:22.9777487Z",
      "id": "",
      "level": "Error",
      "operationId": "a613bc6a-5f61-4064-bea5-83c3af232e68",
      "operationName": {
          "value": "Send Events: Azure Function Output Adapter failed to write events",
          "localizedValue": "Send Events: Azure Function Output Adapter failed to write events"
      },
      "resourceGroupName": "mlIoTPlatformDev",
      "resourceProviderName": {
          "value": "Microsoft.StreamAnalytics",
          "localizedValue": "Microsoft.StreamAnalytics"
      },
      "resourceType": {
          "value": "Microsoft.StreamAnalytics/streamingjobs",
          "localizedValue": "Microsoft.StreamAnalytics/streamingjobs"
      },
      "resourceId": "",
      "status": {
          "value": "Failed",
          "localizedValue": "Failed"
      },
      "subStatus": {
          "value": "",
          "localizedValue": ""
      },
      "submissionTimestamp": "2018-12-18T15:55:04.0799116Z",
      "subscriptionId": "",
      "properties": {
          "Message Time": "2018-12-18 15:54:22Z",
          "Error": "- An error occurred while sending the request.\r\n- The underlying connection was closed: An unexpected error occurred on a send.\r\n- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.\r\n- An existing connection was forcibly closed by the remote host\r\n",
          "Message": "Failed to write events. Error encountered after writing [0] batches., - An error occurred while sending the request.\r\n- The underlying connection was closed: An unexpected error occurred on a send.\r\n- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.\r\n- An existing connection was forcibly closed by the remote host\r\n, : OutputSourceAlias:AzureFunctionOutput;AdapterType:AzureFunction;ShardId:0;",
          "Type": "AzureFunctionOutputAdapterFailure",
          "Correlation ID": "4a9c9b61-631a-4f4f-a403-c2869b2af66c"
      },
      "relatedEvents": []
  }
  </code></pre>
  
  <p>Below is my Azure Function code.</p>
  
  <pre><code>[FunctionName("GetData")]
  public static async Task &lt; HttpResponseMessage &gt; Run(
      [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
      // [SignalR(HubName = "ml-iot-platform")] IAsyncCollector&lt;SignalRMessage&gt; signalRMessages,
      ILogger log) {
      log.LogInformation($ "GetData function triggered with Uri {req.RequestUri}");
      dynamic data = await req.Content.ReadAsAsync &lt; object &gt; ();
      log.LogInformation($ "Data count is {data.Count}");
  
      if (data.ToString().Length &gt; 262144) {
          return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
      }
  
      //await signalRMessages.AddAsync(new SignalRMessage()
      //{
      //   Target = "checkData",
      //   Arguments = new object[] { data }
      //});
  
      return req.CreateResponse(HttpStatusCode.OK, "Success");
  }
  </code></pre>
  
  <p>Have you ever faced this issue?</p>