Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

The underlying connection was closed for concurrent Async request

Posted on by 5

I have added web reference to my C# 4.0 project as OOPostAcknowledge and while i run code in my PC assume my table have 1000 rows so there are 1000 async request made to webservice and getting completed success response for all.

the same C# Windows application when running from windows server 2012 R2 while making 1000 async request only first approx (150 - 200) requests are posted successfully and latest getting error as

"System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive. Inner ExMessage = Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. @ : at System.Web.Services.Protocols.WebClientAsyncResult.WaitForResponse() at System.Web.Services.Protocols.WebClientProtocol.EndSend(IAsyncResult asyncResult, Object& internalAsyncState, Stream& responseStream) at System.Web.Services.Protocols.SoapHttpClientProtocol.InvokeAsyncCallback(IAsyncResult result)"

 

Kindly advise for the same, code below.

private void PostItemMasterAcknowledgment()
{
	try
	{
		var ActTable = DBO.GetSqlcmdDataTable($"SELECT * FROM  [dbo].[TABLE_NAME]");


		var req = new OOPostAcknowledge.WebServicesProcess();
		req.Timeout = 1000 * 60 * 10; // ms * sec * min -- 10 mins
		req.Credentials = myCred;
		bool success = false;
		req.UpdateProcessedItemCompleted += Req_UpdateProcessedItemCompleted;
		foreach (DataRow row in ActTable.Rows)
		{
			try
			{
				req.UpdateProcessedItemAsync(row["No"].ToString(), AckProcessed_From_API_FLAG, success, "", row["Id"].ToString());
			}
			catch (Exception ex)
			{
				Library.WriteError(ex);
			}
		}
	}
	catch (Exception ex)
	{
		Library.WriteError(ex);
	}
	finally
	{
		GC.Collect(); this.Cursor = Cursors.Default;
	}
}


private void Req_UpdateProcessedItemCompleted(object sender, OOPostAcknowledge.UpdateProcessedItemCompletedEventArgs e)
{
	try
	{
		if (e.Error == null && e.success && !string.IsNullOrEmpty(e.ackItemNo))
		{
			DBO.SqlExecuteNonQuery($"UPDATE [dbo].[TABLE_NAME] SET [STATUS] = '{AckPostStatus}', [MODIFIEDDATE] = GETDATE(), [REMARKS]= ISNULL([REMARKS],'') + ':Acknowledged {e.ackItemNo}' WHERE [No] = '{e.ackItemNo}' AND [Id] = {e.UserState.ToString()}");
		}
		else
		{
			Library.WriteError(e.Error);
		}
	}
	catch (Exception ex)
	{
		Library.WriteError(ex);
	}
	finally
	{


	}
}

Hi, have tried the same code in Windows 10 PC and getting the error after 200 async requests out of 1000 request, but the same is working fine in Windows 7 and get a response for all 1000 async requests.

Is there need to do any setting need to be changed for Windows 10/Windows server 2012 to allow more async request?

or any config needs to be added in Application app.config?

The DBO is just a static helper class for all SQL Db operation here is the code for DBO.SqlExecuteNonQuery

public static int SqlExecuteNonQuery(string cmdText)
        {
            var conn = GetSqlConnection();
            try
            {
                using (SqlCommand cmd = new SqlCommand(cmdText, conn) { CommandTimeout = 0 })
                {
                    return cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Library.WriteError(ex);
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }

And the OOPostAcknowledge is the webreference name given for the URL iam trying to post the data (185.64.26.76:7047/.../WebServicesProcess).

And AckPostStatus is string variable with value 'A' (Acknowledged).

This is a C# code written in dotnet 4.0 framework in a windows form application.

I believe this should help to analyse the issue i am facing.

As part of our integration program we are trying to pull data form Microsoft NAV Dynamic ERP where we are shared the JSON API to consume the data for different transactions like Itemmaster, sales,purchase, etc..

As the data load shall not be high we agreed to acknowledge the data once received by unique field in each table.. and data once acknowledged by receiver (me) shall not be send again by the sender (NAV ERP)

Example (Itemcode in Itemmaster, Receiptno on in sales, etc..).

Since the data volume is high considering different tables and we decided to use async to make the process faster .

and since then we are facing the problem mentioned above.

I have discussed with the technical team of Microsoft NAV Dynamics of about this error and they are also unsure of the root cause.

Please help to identify the root cause and where the appropriate solution need to be done.

1. Is there any configuration need to be done at NAV dynamics server to accept the load ?

2. Or do we need to modify the C# code (shown above) to better process to posting ? (There are about 27 JSON API we need to consume on daily basis with over 50K records, the synchronous process is slow and takes hours for posting the 50K+ lines ) hence need a adequate solution.

Kindly help.

https://social.msdn.microsoft.com/Forums/en-US/accbdff1-2299-4518-8c9a-aac995af94eb/the-underlying-connection-was-closed-for-concurrent-async-request?forum=csharpgeneral

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans