0

Getting a strange error from QBFC. This code fails:

        var qbRequest = sessionManager.CreateMsgSetRequest("US", 7, 0);
        qbRequest.Attributes.OnError = ENRqOnError.roeStop;
        var qbQuery = qbRequest.AppendCustomerQueryRq();                
        // Don't get all fields (would take forever) - just get these...
        qbQuery.IncludeRetElementList.Add("ListID");
        qbQuery.IncludeRetElementList.Add("Phone");
        qbQuery.IncludeRetElementList.Add("AltPhone");
        qbQuery.IncludeRetElementList.Add("Fax");
        var qbResponses = sessionManager.DoRequests(qbRequest);// <<- EXCEPTION:  INVALID TICKET PARAMETER !!!

However - if I just put a delay in there it works fine. e.g.

        System.Threading.Thread.Sleep(1000);
        var qbResponses = sessionManager.DoRequests(qbRequest);// <<- WORKS FINE!!

I found this out because anytime I would set a breakpoint in the code to debug the problem - the problem would go away. So then I learned that I could just put a 1 second Sleep in there and simulate the same behavior. (btw - half second delay doesn't help - still throws exception)

This has got me scratching my head. I initialize the sessionManager at the start of the app and reuse it throughout my code. And it works everywhere else in this app but here. I have looked at the raw XML (for both request and response) and don't see anything wrong in there. The response just has an error: "The data file is no longer open. Cannot continue." but nothing to indicate why. (and the data file is open, after this exception I can use it for any number of OTHER things)

I suspect it has something to do with WHEN this code is called. I have a listener that listens for messages from the XDMessaging add-in (used for inter-process communication). When the listener receives a message the event calls this code. But this code is called in the same app (and same thread) as tons of OTHER QBFC code I have that does very similar stuff without a problem. And if it was a threading issue I would think the error would happen regardless of if I Sleep() for a second or not.

Anybody have any ideas?

William Madonna Jr.
  • 242
  • 1
  • 3
  • 12

1 Answers1

0

What version of QBSDK are you using and what version of QuickBooks? I tested using QBSDK 13 (though I specified version 7 when creating the message request), with version 14.0 Enterprise R5P. I experienced no problems or exceptions without having a delay. Perhaps there's something going on with your SessionManager since it appears that you've already opened the connection and began the session elsewhere?

Here's my code that had no problem:

QBSessionManager SessionMananger = new QBSessionManager();
SessionMananger.OpenConnection2("Sample", "Sample", ENConnectionType.ctLocalQBD);
SessionMananger.BeginSession("", ENOpenMode.omDontCare);
IMsgSetRequest MsgRequest = SessionMananger.CreateMsgSetRequest("US", 7, 0);
MsgRequest.Attributes.OnError = ENRqOnError.roeStop;
var qbQuery = MsgRequest.AppendCustomerQueryRq();
qbQuery.IncludeRetElementList.Add("ListID");
qbQuery.IncludeRetElementList.Add("Phone");
qbQuery.IncludeRetElementList.Add("AltPhone");
qbQuery.IncludeRetElementList.Add("Fax");
IMsgSetResponse MsgResponse = SessionMananger.DoRequests(MsgRequest);

for (int index = 0; index < MsgResponse.ResponseList.Count; index++)
{
    IResponse response = MsgResponse.ResponseList.GetAt(index);
    if (response.StatusCode != 0)
    {
        MessageBox.Show(response.StatusMessage);
    }
}
Hpjchobbes
  • 1,309
  • 1
  • 8
  • 11