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
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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;
            }
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top