QuickBooks 检索客户失败

问题描述:

我有这个代码:

protected readonly IMsgSetRequest RequestMsgSet = null;
protected IMsgSetResponse ResponseMsgSet = null;

public string GetAllCustomer(bool IsActiveOnly = true)
{

    RequestMsgSet.ClearRequests();
    ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();

    if (IsActiveOnly)
    {
        if (CustomerQueryRq != null)
            CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
                ENActiveStatus.asActiveOnly);
    }
    else {
        CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
    }
    ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
    return(ResponseMsgSet.ToXMLString());
}

Console.WriteLine(GetAllCustomer());

它返回这个:

<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<CustomerQueryRs requestID="0" statusCode="1000" statusSeverity="Error" statusMessage="There has been an internal error when processing the request." />
</QBXMLMsgsRs>
</QBXML>

我怀疑 DoRequests 内存不足,因为我有 110,000 个客户.

I suspect that the DoRequests runs out of memory as I have 110,000 customers.

如何确认 DoRequests 内存不足?

How can I confirm that DoRequests is running out of memory?

如何重写此代码以使用更少的内存?

How can I rewrite this code to use less memory?

看看 ICustomerQuery

您可以使用过滤器获取数据,例如:名称范围(a-i,j-r 比 s-z)过滤器、日期范围过滤器、名称以过滤器开头以及其他一些过滤器.

You can get data with filtering's such as: name range (a-i, j-r than s-z) filter, date range filter, name starts with filter and other some filters as well.

这也可用于仅获取您想要的内容,例如:FullNameAccountNumber.

Also this can be used to get only the things you want like: FullName and AccountNumber.

通过这种方式,您可能会消耗更少的内存.看看下面的示例代码:

In this way you may consume less memory usage. Have a look at below sample code:

public IList<CustomerModelQB> GetAllCustomer(string fromName = "a", string toName = "z", bool IsActiveOnly = true)
    {
        RequestMsgSet.ClearRequests();
        ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();

        if (IsActiveOnly)
        {
            if (CustomerQueryRq != null)
                CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
                    ENActiveStatus.asActiveOnly);
        }
        else
            CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);

        //CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(3);

        //Set field value for FromName
        CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.FromName.SetValue(fromName);
        //Set field value for ToName
        CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.ToName.SetValue(toName);

        CustomerQueryRq.IncludeRetElementList.Add("FullName");
        CustomerQueryRq.IncludeRetElementList.Add("AccountNumber");
        ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
        return WalkCustomerQuery(ResponseMsgSet);
    }

进一步,您可以参考this问题以了解字母顺序事情的突破.

Further you may refer to this question for alphabetical breakout of things.