6

I am getting error -2147220472 when I try to connect to Quickbooks. The application is executed by a windows service. The log file is as follows:

I   8788    RequestProcessor    ========= Started Connection =========
I   8788    RequestProcessor    Request Processor, QBXMLRP2 v12.0
I   8788    RequestProcessor    Connection opened by app named 'QBWatcher'
I   8788    RequestProcessor    OS: Microsoft Professional (build 9200), 64-bit
I   8788    RequestProcessor    Current Process is elevated
I   8788    RequestProcessor    Current User is in AdminGroup
I   8788    RequestProcessor    Current Process is ran as Admin
I   8788    RequestProcessor    Current Process Integrity Level : 3000
I   8788    RequestProcessor    Previous instance of QB is going down..! Wait and retry to get a new instance.
I   8788    RequestProcessor    Previous instance of QB is going down..! Wait and retry to get a new instance.
I   8788    RequestProcessor    Previous instance of QB is going down..! Wait and retry to get a new instance.
I   8788    RequestProcessor    Previous instance of QB is going down..! Wait and retry to get a new instance.
I   8788    RequestProcessor    Previous instance of QB is going down..! Wait and retry to get a new instance.
E   8788    RequestProcessor    Could not find or create an instance of QuickBooks using InstanceFinder
I   8788    RequestProcessor    Connection closed by app named 'QBWatcher'
I   8788    RequestProcessor    ========== Ended Connection ==========
I   8788    CertVerifier    The file does not contain an Authenticode signature.

This actually works at times, but I can't see a pattern. What might be causing this?

In a nutshell, the code being used to connect is as follows:

qbxmlConn.OpenConnection2(filename, "QBWatcher", QBXMLRP2Lib.QBXMLRPConnectionType.localQBD);
QBXMLRP2Lib.IAuthPreferences qbAuthPrefs = qbxmlConn.AuthPreferences;                                   
qbAuthPrefs.PutPersonalDataPref(QBXMLRP2Lib.QBXMLRPPersonalDataPrefType.pdpNotNeeded);
qbAuthPrefs.PutUnattendedModePref(QBXMLRP2Lib.QBXMLRPUnattendedModePrefType.umpOptional);
ticket = qbxmlConn.BeginSession(filename, QBXMLRP2Lib.QBFileMode.qbFileOpenDoNotCare);
Evil August
  • 411
  • 6
  • 18
  • What code do you use to connect? – Gabe Jan 03 '14 at 13:44
  • You got the error code wrong, it is -2147220472. In hex that's 0x80040408. This first google hit tells you about it. – Hans Passant Jan 03 '14 at 13:57
  • Possible duplicate of [QBWC1013: Error connecting to QuickBooks. 0x80040408](http://stackoverflow.com/questions/15953163/qbwc1013-error-connecting-to-quickbooks-0x80040408) – Hans Passant Jan 03 '14 at 13:58

1 Answers1

9

This is the key to this question:

The application is executed by a windows service.

Due to the way QuickBooks works, trying to connect to QuickBooks from a Windows service (e.g. a little program that sits and runs in the background instead of an end-user program with a GUI) will never work reliably.

QuickBooks uses a GUI message pump to power the SDK - so if there's no GUI available (e.g. like in a Windows service that runs even when there are no users logged on to the machine) then the SDK/API won't be available.

Sorry for the bad news. :-/

Can you make your program have a simple GUI and only run when a user is logged on (lock the screen if they need to leave the computer) instead?

Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
  • This is what I feared. I'm trying to persuade the powers at be to let me run this as a forms application minimized to the task tray. Also, if I'm understanding this correctly, the service would not work without the user logged in anyway, which is why they are telling me we need a service in the first place. – Evil August Jan 03 '14 at 19:50
  • Keith, do you have any insight on why when using a Windows service it works sometimes and not others? – Evil August Jan 06 '14 at 12:44
  • Something that I didn't mention, the process that is executed by the service is in fact a GUI application and it is the process that actually connects to Quickbooks. Do you think this should work Keith? – Evil August Jan 08 '14 at 16:44
  • If it's running as a Windows service, it won't execute reliably. It has to be running as a normal program, started from a normal logged on user session. – Keith Palmer Jr. Jan 08 '14 at 18:24
  • @KeithPalmerJr. In your blog you mentioned that this could work by configuring `qbXMLRP2e` in dcomcnfg, is that still true? – Mayank Apr 18 '18 at 14:58
  • I doubt it. I wouldn't even attempt it, or expect it to be reliable. – Keith Palmer Jr. Apr 18 '18 at 21:40