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