6

I perform tech support and some development on a number of programs that uses the QuickBooks SDK to perform a variety of functions. Lately I have been noticing that when the user does the following:

Pre-Requisites: - QuickBooks is NOT open on the desktop and is not currently running. - My desktop program is NOT set up in the QuickBooks integrated application list to log in automatically.

1) Opens one of my programs.

2) Performs an action that starts a connection and a session with QuickBooks.

3) The QuickBooks interface returns an error saying you must have QuickBooks open and signed into the company file to perform this action.

4) My program closes the session and the connection and then presents the user with some dialog giving them troubleshooting tips.

Result:

QuickBooks itself continues to run in the background afterwords as QBW32.exe, even though the session and the connection were both closed.

If the user then tries to open up the QuickBooks desktop program, they get an error telling them that QuickBooks is already running. They then have to open up the task manager in windows and close the running QBW32.exe before they can successfully open up QuickBooks.

I have reproduced this this using a very basic C# program that I have written below.

In the test app, I am using the following steps/scenario:

Prerequisite: 1) The test application is NOT set to log in automatically to QuickBooks. It is set to log in only when the user has QuickBooks desktop program open and they have an open company file.

2) Ensure QuickBooks is NOT open prior to the test below.

Steps:

1) Open the test C# application

2) Push the button that says "Open Connection." A connection should be opened up with QuickBooks' interface via the QBXML interop.

3) Push the button that says "Start Session". A session should be started with QuickBooks.

4) Assuming the test pre-requesities are fulfilled up above, you should receive an error message returned from QuickBooks telling you the application is NOT set up to log in automatically and you will need to open up QuickBooks before you can attempt a session.

5) The QBW32.exe should now be running in the background.

6) Press the button that says end session. This should end the session using the QuickBooks interface. The session should already be ended via the try-catch in step 3's button, regardless.

7) Press the button that says "Close Connection". This should close all connections with QuickBooks.

8) The QBW32.exe is still running in the background, even though the session and connection have both been ended and closed.

9) Close the test application using the exit button.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Interop.QBXMLRP2;

namespace Open_Connection
{

    public partial class Form1 : Form
    {

        bool sessionBegun = false;
        bool connectionOpen = false;
        RequestProcessor2 rp = null;
        string ticket;


        public Form1()
        {
            InitializeComponent();
        }

        private void End_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void OpenConn_Click(object sender, EventArgs e)
        {
            try
            {  //Start a new connection with QuickBooks
                rp = new RequestProcessor2();
                rp.OpenConnection2("", "Open Connection", QBXMLRPConnectionType.localQBD);
                connectionOpen = true;
            }

            catch (Exception connectionException)
                { //If the connection fails, close the connection to avoid the program from getting stuck in an interop error loop.
                        MessageBox.Show(connectionException.Message, "Error");
                        if (connectionOpen)
                        {
                            rp.CloseConnection();
                        }
                }
        }

        private void StartSess_Click(object sender, EventArgs e)
        {
            try
            {  //Start a new session with QuickBooks using the company file specified below.
                string ticket = rp.BeginSession(@"C:\Users\username\Documents\Quickbooks Company Files\example.QBW", QBFileMode.qbFileOpenDoNotCare);
                sessionBegun = true;
            }
            catch (Exception sessException)
            {
                //If the session fails (I.E. QuickBooks is not open with a user logged into the company file and the program is not given permission to
                //automatically log in, imeedietly end the session and close the connection.
                MessageBox.Show(sessException.Message, "Error");
                if (sessionBegun)
                {
                    rp.EndSession(ticket);
                }

                if (connectionOpen)
                {
                    rp.CloseConnection();
                }
            }
        }

        private void EndSess_Click(object sender, EventArgs e)
        {
            try
            { //End the session 
                rp.EndSession(ticket);
                sessionBegun = false;
            }

            catch (Exception ex)
            { //If a session was not started already, set the session begun flag to false to avoid getting stuck in a loop. 
                sessionBegun = false;
            }

        }

        private void CloseConn_Click(object sender, EventArgs e)
        {
            try
            { //Close the connection to QuickBooks 
                rp.CloseConnection();
                connectionOpen = false;
            }

            catch (Exception ex)
            { //If the connection was not open, set the connection open flag ot false to avoid getting stuck in a loop.
                connectionOpen = false;
            }

        }
    }
}

Based on the example program I have up above, is there any thing that I could be doing to have the QBW32.exe close by itself so it does not stay running in the background under the scenario I described up above?

Update: Myself and numerous other users already have tried turning off the setting "Keep Quickbooks Running for faster startup" in the preferences section of QuickBooks. This does not prevent the QBW32.exe from staying open in the background after the session and connection are both ended. I am seeing this behavior occur with QB 2013 thru 2015.

Stevie White
  • 569
  • 1
  • 7
  • 24

4 Answers4

4

After doing some further testing using the scenario that Geetanjali presented, I have arrived at this conclusion:

  • The QBW32.exe only closes itself if you have your program set up on the integrated applications list in QB to log in automatically.

  • If you have your program NOT set up to log in automatically, the QBW32.exe will open up the moment you start a session when you pass in a company file name and will remain open even if you end the session and end the connection.

  • The QBW32.exe does NOT start if there is no company file passed in when starting the session.

I have confirmed somewhat with William on the Intuit forums that this appears to be working as intended.

To work around this, I have done this in my test application:

I added an extra if block around the session start to first send a connection test via an open session call without a company file specified. This forces the interface to return an error telling me I cannot start a session because no company file is specified and QuickBooks is not open. This subsequently forces my test app to display a message telling me to open the company file before trying again.

I imagine that I can further build upon this by adding a setting to 'use log in automatic mode' and 'regular mode' so that the test connection can be skipped when desired if I actually want to use log in automatic.

Regardless, this seems to be the only way around this scenario, beyond adding a code block that kills the QBW32.exe process. This isn't exactly desirable, but it is also an option.

Anyway, I hope this helps anyone who runs into this hurdle in the near future.

Update As of 9/12/17:

It seems that starting with QuickBooks 2016, this behavior is no longer a problem. Regardless of whether or not you pass in a company file with or without automatic login, when you start a session, the QBW32.exe will open up afterward when the user tries to run the executable either directly or via the desktop/start menu shortcut(s). What's interesting is that the QBW32.exe process may already be running in the background from you having passed in a company file without automatic login. Still, regardless, the user can open up QuickBooks and they will not receive the message stating that QuickBooks is already running.

I've tested this with QuickBooks Enterprise 2016 and Enterprise 2017. All of our users who have at least QuickBooks 2016 (various editions, Pro, Premier etc) have not complained about the aforementioned problem either. I am going to go out on a limb here and guess that Intuit decided to fix the problem either intentionally or unintentionally.

Thus I only recommend the above approach if you or a user of your integrated app is still using a version of QuickBooks below QuickBooks 2016.

InteXX
  • 6,135
  • 6
  • 43
  • 80
Stevie White
  • 569
  • 1
  • 7
  • 24
  • 1
    As of 2019-12-5 it seems this may still be a problem. I have an open support question on the QB SDK forum. In the meantime, the process kill solutions works, but it's awfully inelegant. – Bob Mc Dec 05 '19 at 23:38
  • 1
    @BobMc Agreed, it is a very inelegant solution. Unfortunately the QuickBooks SDK doesn't (or at least to my knowledge), provide you with any other alternative. I haven't worked with QB for about 3 years now though. I would wager that Intuit may have made a mistake if this problem is back. What version are you seeing this in, 2019? It may be worth referencing this post as evidence that this problem was fixed at some point and it has now suddenly returned. – Stevie White Dec 07 '19 at 03:41
  • This is QB Desktop Enterprise 2020 Manufacturing and Wholesale. While I will admit that I am hardly an expert on the QB SDK, I believe I'm doing everything as prescribed. This SO thread is one of the few articles I've seen with relevant questions and information with regard to this particular issue. Thanks for your excellent answer. – Bob Mc Dec 08 '19 at 04:13
4

I can tell you from years of experience of using the desktop SDK from C# that you're not alone. Intuit is aware of it, and it has nothing to do with the "keep running" option. I've chatted with Intuit support staff; some believe it's a bug and some believe it's by design.

I've got a WinForms app that has been in production since QuickBooks 2006, and starting around 2011 (Enterprise 11), this problem of the process hanging around started. As of 2013, even the SDK's tester app ("SDK Test Plus 3") would do the same behavior as your tester app.

My app is run on many PC's at my client, however the part that communicates with QB would call to the instance of QB on their server (not QB installed on their PC's), and I chose to use the "Kill QBW32 if it won't close" idea. In 2014 I changed it to communicate with QB on their desktop (since they have QB on their PC) and NOT use the kill technique (because they may be running QB at the same time). Because of this change, I haven't had to worry about QBW32 still running and I haven't had any problems (my client is the type to let me know).

Gen1-1
  • 424
  • 5
  • 9
  • Wlluam Lorfing with Intuit opened up a support ticket regarding this after I questioned whether or not this behavior was by design. While I would like to think something may come of it, I am under the impression that Intuit has higher priorities. Personally I think they are considering retiring or phasing out the desktop version of QB. They certainly are putting more of their emphasis on QB Online. How much longer the desktop version will be supported is something we have to wait and see. – Stevie White Aug 31 '15 at 04:34
0

If your QuickBooks is running in background then perform below steps:

Turn off the "Keep QuickBooks running for quick startups" preference in QuickBooks 2011 or later.

  1. Open QuickBooks and open your company file.
  2. Choose Edit > Preferences.
  3. Choose the General icon in the list on the left.
  4. Choose the My Preferences tab at the top.
  5. Click to clear the Keep QuickBooks running for quick startups checkbox.
  6. Click OK.

After you close QuickBooks or restart your computer, QuickBooks will not run in the background.

  • I already have this setting turned off in the general preferences tab in Quickbooks. I am seeing this problem occur with QB 2013 thru 2015. – Stevie White Jun 30 '15 at 11:36
  • Are you doing an AccountQuery with a Modified Date Range in the request? – William Lorfing Jun 30 '15 at 15:21
  • William - If you look in the simple app code that I posted up above, I am not using any XML queries. I am simply opening a connection and starting a session. – Stevie White Jun 30 '15 at 15:48
0

I have tried the following: Open SQL Server Management Studio, run an Integration package that queries QuickBooks (QuickBooks will start automatically in the background), then close SQL MS completely. I can confirm that QBW32.EXE is then still running, and the service that accessed QB is no longer running.

The calling application must always close the connection. Terminating the calling application kills the application not the connection. When using MS SQL Server you need to link and unlink QODBC.

For example:

EXEC sp_addlinkedserver @server = N'QODBC', @srvproduct=N'QODBC', @provider=N'MSDASQL', @datasrc=N'QuickBooks Data', @provstr = 'ODBC;DSN=QuickBooks Data;DFQ=C:\Program Files\QODBC Driver for QuickBooks\sample04.qbw;SERVER=QODBC;UseDCOM=Y; OptimizerDBFolder=C:\Program Files\QODBC Driver for QuickBooks\Optimizer; OptimizerAllowDirtyReads=Y'

EXEC sp_dropserver @server = N'QODBC'

Hope this helps you.

  • The example you are using seems to be using a scenario where QODBC is already set to log in automatically. The test C# program that I shared up above is NOT set to log in automatically. – Stevie White Jul 06 '15 at 03:31
  • I've gone ahead and elaborated on the test steps I am using with the test program that I shared the code for up above. At this point I am just trying to narrow down what can be done to close the QBW32.exe via the test app via the SDK (WITHOUT issuing commands through Windows to kill the QBW32.exe). I think at this point there may be a problem with the SDK when your application is not set to log in automatically and you try to start/end a session and connection. Due to my company's policy, we are not set our applications to log in automatically due to the problamatic nature of auto login. – Stevie White Jul 06 '15 at 03:52