The "BeginSession" method has not been called or it did not succeed - QBFC SDK12 and ASP.NET WebSite

StackOverflow https://stackoverflow.com/questions/20877440

  •  23-09-2022
  •  | 
  •  

Question

I have the following code

    QBSessionManager sessionManager = new QBSessionManager();
    RequestProcessor2Class requestProcessor = new RequestProcessor2Class();

    try
    {
        IMsgSetRequest msgSetRequest = sessionManager.CreateMsgSetRequest("US", 13, 0);
        msgSetRequest.Attributes.OnError = ENRqOnError.roeStop;

        // Query all the customers
        ICustomerQuery customerQuery = msgSetRequest.AppendCustomerQueryRq();
        customerQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);
        customerQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue(customerName);


        inputRequestXML = msgSetRequest.ToXMLString();


         requestProcessor.OpenConnection("QBWebSite", "QuickBooks");
        ticket = requestProcessor.BeginSession("$Path\\sample_consulting business.qbw",QBFileMode.qbFileOpenDoNotCare);

        response = requestProcessor.ProcessRequest(ticket, inputRequestXML);
        responseTextbox.Text = response;

While postback of the page it throws the "The "BeginSession" method has not been called or it did not succeed" and the COMException is "[COMException (0x8004040c): The "BeginSession" method has not been called or it did not succeed.]"

What am I doing wrong. Please help

I am using the quickbooks 14 enterprise version with .NET 4.0 framework. I made sure that the 32 bit flag is set to true in IIS.

Was it helpful?

Solution

As the error says, you need to call BeginSession on the SessionManager before you create your request. This is the connection code that I use as a template:

          

QBSessionManager SessionManager = null;

        try
        {
            SessionManager = new QBSessionManager();
            SessionManager.OpenConnection2("AppID", "AppName", ENConnectionType.ctLocalQBD);
            SessionManager.BeginSession("", ENOpenMode.omDontCare);
            IMsgSetRequest MsgRequest = SessionManager.CreateMsgSetRequest("US", 13, 0);
            MsgRequest.ClearRequests();
            MsgRequest.Attributes.OnError = ENRqOnError.roeStop;

            // Create request here ///////////////////////////////////////////                               
        }
        catch (Exception ex)
        {
            // Log or display the error
        }
        finally
        {
            if (SessionManager != null)
            {
                SessionManager.EndSession();
                SessionManager.CloseConnection();
                SessionManager = null;
            }
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top