Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4126300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:58:58+00:00 2026-05-20T23:58:58+00:00

I’m being forced to connect to some .net service in a VBA tool I’m

  • 0

I’m being forced to connect to some .net service in a VBA tool I’m developing. I use a function to return the cached instance or create a new one if it hasn’t been created yet.

If anything goes wrong with the object (such as a connection time out), the next time I try to use it, I get the error

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

I’ve seen this error pop up all over the web, but all in proper languages that have try-catch blocks.

Rather than waiting for this error to occur when the cached instance gets used and dealing with it in an “On Error Goto” statement, I’d like to prevent it by happening when the cached object is retrieved for use. I couldn’t find an object model for this thing anywhere, and setting up a watch on the initialized object just shows . What property or test can I use at retrieval time to determine whether the object is in a faulted state?

Private Function GetMRLDIntegrationService() As Object
    Const ServiceAddress = "service:mexAddress=""net.tcp://hydfwdvweb001/Integration/MrldIntegrationService.svc/Mex""," & _
            "address=""net.tcp://hydfwdvweb001/Integration/MrldIntegrationService.svc/""," & _
            "contract=""IMrldSimplexIntegration"", contractNamespace=""http://tempuri.org/""," & _
            "binding=""SimplexIntegration"", bindingNamespace=""http://tempuri.org/"""
    Static cachedInstance As Object
    If Not cachedInstance Is Nothing Then
        ''//If *DETECT ERROR STATE HERE* Then Set cachedInstance = Nothing
    End If
    If cachedInstance Is Nothing Then Set cachedInstance = GetObject(ServiceAddress)
    If cachedInstance Is Nothing Then Err.Raise 1, , _
        "The MRLD server did not respond to the request to provide the service object."
    Set GetMRLDIntegrationService = cachedInstance
End Function

Elsewhere, in another method, this is where the error occurs, and this is when it’s too late to deal with the error elegantly:

Private Sub FillFromRiskID(ByVal riskID As String)
    ...
    Process_MRLD_Result GetMRLDIntegrationService().GetSerializedRisk(riskID, "1", uName, pWord)
    ...
End Sub

Thanks for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:58:59+00:00Added an answer on May 20, 2026 at 11:58 pm

    This alternate solution give the GetService function an option to reset the cached object (i.e. if an error occured), the problem is that I cannot find a way to use this feature such that the Faulted state error can easily be reset, but other errors do not result in redundant erronous requests before the actual error gets processed.

    Private Function GetMRLDIntegrationService(Optional ByVal reset As Boolean = False) As Object
        Const ServiceAddress = "service:mexAddress=""net.tcp://hydfwdvweb001/Integration/MrldIntegrationService.svc/Mex""," & _
                "address=""net.tcp://hydfwdvweb001/Integration/MrldIntegrationService.svc/""," & _
                "contract=""IMrldSimplexIntegration"", contractNamespace=""http://tempuri.org/""," & _
                "binding=""SimplexIntegration"", bindingNamespace=""http://tempuri.org/"""
        Static cachedInstance As Object
        If reset Then Set cachedInstance = Nothing
        If cachedInstance Is Nothing Then Set cachedInstance = GetObject(ServiceAddress)
        If cachedInstance Is Nothing Then Err.Raise 1, , _
            "The MRLD server did not respond to the request to provide the service object."
        Set GetMRLDIntegrationService = cachedInstance
    End Function
    

    And the calling function:

    ''/*If the cached object is in an error state there's no way to detect it without making a request, but
    'making even a dummy request each use just to check would waste dozens of precious seconds per request,
    'so this routine carefully makes the intended request, catches the error that might occur, then resets
    'the connection and tries the request again. The upside is that a service object in an error state
    'will be resolved immediately and transparently by opening a new connection as needed. The downside
    'is that if any other error occurs (such as a 1 minute timeout error), the first occurrence will
    'be a non-breaking error and it will actually repeat the error a second time before notifying the user,
    'doubling the amount of time it takes any error to propogate. (In the case of a 1 minute time-out
    'occurring, the request would occur twice for a total of 2 minutes delay until the application becomes
    'responsive again.)*/
    Private Sub FillFromRiskID(ByVal riskID As String)
        Const uName As String = "perftest1"
        Const pWord As String = "****"
        Dim result As String
    
        On Error GoTo retryGet
        Process_MRLD_Result GetMRLDIntegrationService().GetSerializedRisk(riskID, "1", uName, pWord)
        GoTo finally
    retryGet:
        Resume retryGet2: 'Resets the error state so that a new error can be thrown
    retryGet2:
        On Error GoTo invalidConnection
        Process_MRLD_Result GetMRLDIntegrationService(reset:=True).GetSerializedRisk(riskID, "1", uName, pWord)
    finally:
        Exit Sub
    invalidConnection:
        MsgBox "Error connecting to MRLD: " & Err.Description, vbCritical, "Fill From MRLD"
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.