web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Error in Webservice - System.Runtime.InteropServices.COMException : The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

(0) ShareShare
ReportReport
Posted on by

Hi,

We are having problems with GP Webservice call that looks like this:

invItem = wsDynamicsGP.GetInventoriedItemByKey(orderedItem, context);

It works for a while, then we start getting the following eeror in the GP Exception Log:

System.Runtime.InteropServices.COMException : The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE)).


Restarting the Microsoft Dynamics GP Service Host service fixes this problem. It seems to be ocuring once or twice a day. Does anyone know how to resolve this?  We are running GP2013R2.

Thank you, Bob

*This post is locked for comments

I have the same question (0)
  • DavidMO Profile Picture
    1,030 on at

    We are seeing this every few weeks I production. I saw another thread with the 2010 version of Web Services, saying it was a known issue with Microsoft. Anyone have a solution?

  • Midmichael Profile Picture
    59 on at

    I have seen this with a couple of our clients - but we have not determined the exact cause yet. I have the service restarting periodically which helps, but does not completely eliminate the issue. I have seen it with GP2010 and GP2013R2. I'm hoping that keeping this topic current will eventually effect a solution.

  • Suggested answer
    DavidMO Profile Picture
    1,030 on at

    Here is some feedback I received from Microsoft via our GP partner

    Summary of issue:

    • The connection that is established between the Dynamics Security Service for Web Services security store is getting “dropped” sporadically which causes any subsequent calls to the security store fail. This exception is getting logged in the Web Service exception console.

     

    • Somewhere within the infrastructure of that deployment, there is an issue either between the Servers and/or Virtual Machine and it’s Host or the Host and the SQL Server. The way the code is written today, we are expecting that connection to be there and constant. We DO NOT have any additional code that can detect if the connection is gone OR handle the exception when we make a call and the connection is no longer there. The best scenario would be for the code to handle the exception and then spin up a new connection to the SQL Server. This way, even though there are problems with the infrastructure, the software handles the problem and continues to work. (Enhancement request, anyone?)

     

    In dealing with these types of issues, you typically need to work with the windows platforms team. What they will do is gather all of the information from the physical host and servers/virtual machines/etc. involved and verify that the BIOS and drivers for both systems are at their latest revisions. They would also have you make sure that the latest public release of service packs for the SQL and SQL Servers have also been applied.

     

    The only other thing I can offer is something that we looked at previously with Web Services but never really verified the success of it. If you get a corresponding error or log in Event Viewer when this issue happens, you could potentially use the ‘attach task to this event’ functionality where each time the exception is thrown, it would run a batch file, for example, to stop and restart the Dynamics GP Service Host service, which is the resolution you’re currently using. We have gotten this to work in a controlled environment, but haven’t tested extensively with customer or partner issues. The worst case scenario with this, would be that the Dynamics GP Service Host service is restarted all the time, depending on what is listed in the Event Viewer log.

  • Mitch.M Profile Picture
    532 on at

    How is this not fixed yet?

  • DavidMO Profile Picture
    1,030 on at

    A good question. Microsoft has taken this as a suggestion ( I did get some votes, but not as many as I would have liked), but since the issue has been known and reported for years, I would not hold any deep breaths.

    Once the error starts, the GP Web Service is neither completely up or stopped. It takes a Kill commend to get rid of it. I ended up writing some PowerShell script to detect this specific error and running the kill command, then restart the Service. It works well enough, so we are not down for more than 5 minutes or so when it occurs.

  • Mitch.M Profile Picture
    532 on at

    It's just a little frustrating. For me the biggest problem is you can't even be proactive with the issue; you can only catch it after the fact. And even if we do catch it and restart immediately you have to deal with those original transactions that were sent and failed.

    For one client we know they will receive transactions starting at 11 PM. So we proactively restart the services right before. But it still breaks randomly.

  • Rob Klaproth Profile Picture
    1,730 on at

    Hi David,

    Would you mind sharing the script that you created to restart?

  • DavidMO Profile Picture
    1,030 on at

    Sure. These are my first pair of PowerShell scripts, a batch file, plus a Windows Scheduler task that runs every 5 minutes. It does it's job and has kept us running.

    ReadDynamicsEventLog2.ps1

    # David Morinello 04/19/2016

    $Event = get-eventlog -logname Dynamics -EntryType Error -After (Get-Date).AddMinutes(-5) | where-object  {$_.Message -like "*Exception from HRESULT*"}

    If ($Event.length -gt 0) {

       #Write-Output "Event Exists"

       cmd.exe /c '\Automations\RestartGPWebServices.bat'

       }

       #Else {"No Event"}

    Exit

    --------------------------------------------

    RestartGPWebServices.bat

    Net Stop DynGPWebService

    Timeout /t 10 /nobreak

    REM Alternate killer of the GP Web Service (DPM)

    Echo Off

    FOR /F "tokens=3" %%A IN ('sc queryex DynGPWebService ^| findstr PID') DO (SET pid=%%A)

    IF "!pid!" NEQ "0" (

     taskkill /F /PID %pid%

    )

    Timeout /t 10 /nobreak

    Net Start DynGPWebService

    Timeout /t 10 /nobreak

    Powershell.exe -executionpolicy remotesigned -File C:\Automations\RestartGPWebService_Email.ps1

    ----------------------------------------

    RestartGPWebService_Email.ps1

    # David Morinello 04/19/2016

    send-mailmessage -to "David.Morinello <David.Morinello@eMAILSERVER.COM.com>" -from "noreply@eMAILSERVER.COM.com" -subject "GP Web Service on ASC-STG-GPWB03 has restarted" -Body "The GP Web Service on ASC-STG-GPWB03 has restarted due to a detected Error Event" -SmtpServer "mail.eMAILSERVER.COM.com"

    send-mailmessage -to "David.Morinello <DMorinelloii@yahoo.com>"             -from "noreply@eMAILSERVER.COM.com" -subject "GP Web Service on ASC-STG-GPWB03 has restarted" -Body "The GP Web Service on ASC-STG-GPWB03 has restarted due to a detected Error Event" -SmtpServer "mail.eMAILSERVER.COM.com"

    #send-mailmessage -to "John.Steyer <John.Steyer@eMAILSERVER.COM.com>"         -from "noreply@eMAILSERVER.COM.com" -subject "GP Web Service on ASC-STG-GPWB03 has restarted" -Body "The GP Web Service on ASC-STG-GPWB03 has restarted due to a detected Error Event" -SmtpServer "mail.eMAILSERVER.COM.com"

    send-mailmessage -to "CorpAppsAlerts@eMAILSERVER.COM.opsgenie.net"           -from "noreply@eMAILSERVER.COM.com" -subject "GP Web Service on ASC-STG-GPWB03 has restarted" -Body "The GP Web Service on ASC-STG-GPWB03 has restarted due to a detected Error Event" -SmtpServer "mail.eMAILSERVER.COM.com"

    ----------------------

    Windows Task Scheduler Task

    Calls a PowerShell script ReadDynamicsEventLog2.ps1 to check the Dynamics Event log for a "Handle is invalid" error. PS Script calls RestartGPWebServices.bat batch if true. Emails are handled by RestartGPWebService_Email.ps1

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans