2

I'm trying to help a client who has a web application (ASP/C#) that integrates with Quickbooks via the QBXML SDK.

I want to open up a connection to an already active QuickBooks instance in a user session.

The relevant code in question:

    if (rp == null)
        rp = new RequestProcessor2();

    if (!connected)
    {
        rp.OpenConnection2("IMS", "Internal Management System", QBXMLRPConnectionType.localQBD);
        connected = true;
    }

    if (xticket == null)
        xticket = rp.BeginSession(cfg.qbfile, QBFileMode.qbFileOpenMultiUser);

As is, this will attempt to launch a new instance of Quickbooks via DCOM, which is not a viable option. Following the QBSDK documention, I attempted to pass null to BeginSession's first argument, which should use the open qbw file.

However, instead of the expected action of connecting to the running instance of Quickbooks, it launches a new instance, eventually yielding the error:

"If the QuickBooks company data file is not open, a call to the "BeginSession" method must include the name of the data file."

The IIS AppPool running the web app uses the same user as the Quickbooks instance I'm trying to connect to.

This was all set up by a third party who is no longer available, and, of course, they left no documentation whatsoever on how this system was supposed to work. Any assistance would be welcome.

Kal Zekdor
  • 1,172
  • 2
  • 13
  • 23

2 Answers2

1

I'm trying to help a client who has a web application (ASP/C#) that integrates with Quickbooks via the QBXML SDK.

Unfortunately, this approach will not work.

It's a well-known limitation of QuickBooks that:

  1. QuickBooks has to be running in the user session you're trying to connect from
  2. QuickBooks has to have access to a GUI (it uses a GUI message pump to function)

Because your web app is running in from within IIS, neither of those two criteria are met, and connections to QuickBooks will fail. You should be using the QuickBooks Web Connector instead.

I want to open up a connection to an already active QuickBooks instance in a user session.

Unfortunately, QuickBooks won't allow this.

Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
  • Web connector is not a viable option at this time, as it would require a complete redesign of a legacy app. Further, you seem to be saying that it is both impossible and required to run quickbooks in a user session. Moreover, the app in question does successfully connect to a quickbooks instance launched automatically by DCOM. I have no idea how, mind, but it does. – Kal Zekdor Jan 16 '15 at 13:05
  • Where did I say it's impossible to run QuickBooks in a user session? The only supported way (and only reliable way) of doing what you're asking is to have the web app itself running in the same normal user GUI session that QuickBooks is running in. – Keith Palmer Jr. Jan 16 '15 at 16:05
  • You said Quickbooks won't allow me to connect to an instance running under a user session. (Last sentence of the answer.) I'm probably misunderstanding some part, which is why I asked for clarification. Also, reliable or supported is irrelevant here, only possible matters. This is a legacy app made by an unreliable third party. The ultimate goal is a complete rewrite, but my client can't afford to have this down until then, so I need to fix this hacked together black box first. – Kal Zekdor Jan 16 '15 at 16:28
  • Some additional background on the problem: As I mentioned, as is, the app will launch an instance of Quickbooks via DCOM (under the same user as the console session, but a different Logon Session). It opens the company file. However, the Quickbooks instance in question (since an upgrade) will display a modal dialog, waiting for user input. However, Quickbooks will not respond to COM requests while a modal dialog is open, and I have no means (that I have found) to dismiss said dialog, as the GUI is in a different Logon Session. – Kal Zekdor Jan 16 '15 at 16:35
  • To the best of my knowledge, and according to everything Intuit support and docs say - you can't open up a connection to QuickBooks from within an IIS instance to a QuickBooks session running in a separate user session. That's what I meant by my last sentence. – Keith Palmer Jr. Jan 19 '15 at 01:42
  • Do you know what prevents this? The Quickbooks SDK is designed to allow third party apps to interface with Quickbooks. Further, both the app in question and Quickbooks are running as the _same Windows user_. – Kal Zekdor Jan 19 '15 at 23:25
  • I don't know the exact technical details -- probably no one knows except Intuit employees. But Intuit employees have said many, many, *many* times on their forums over and over and over again that connecting to QuickBooks directly from within IIS won't work. – Keith Palmer Jr. Jan 27 '15 at 20:07
  • My research indicates that it is to do with the means that QB interfaces with the COM service. Something about it refuses to cross LSA Logon Sesssions. Somehow this guy managed to get Quickbooks to launch in the same Logon Session as the asp.net code run by IIS. Maybe I should look into a COM proxy... – Kal Zekdor Jan 27 '15 at 20:53
1

I managed to create an acceptable workaround to my problem, for anyone trying something similar. (Which, honestly, I don't recommend. I'm working with legacy code here.)

First, a brief overview of my research:

The QBXml interface with QuickBooks uses COM requests in order to communicate. Now, for whatever reason, whether design, bug, or limitation in COM, Quickbooks cannot communicate across LSA Logon Sessions. In practice, this means that the same console session that Quickbooks is running under must also run the QBXml code. Additionally, both Quickbooks and your application must have the same UAC elevation status.

I found no way to get IIS to reliably launch Quickbooks. The individual who setup this system before me managed to do so through some very... unorthodox methods. It was incredibly flaky, and the cause of multiple issues.

Regardless, I did manage an acceptable workaround, in the form of IIS Express. IIS Express can run under a standard user session. As such, running both Quickbooks and the web app (through IIS Express) under the same Logon Session allowed them to communicate successfully.

It is not a permanent solution, as there are drawbacks to running a service such as this in a standard user paradigm, but it is an acceptable workaround, and will allow my client to run their business while we refactor. I plan to first decouple the portions of the app that communicate with Quickbooks, moving them into their own codebase. This will allow the web facing portions of the app to operate in a more standard manner, and communicate with the QB integration code through a more reliable means than COM calls.

Thanks to Keith Palmer for helping point me in the right direction.

Kal Zekdor
  • 1,172
  • 2
  • 13
  • 23