0

I am a long time c# developer but brand new to QBFC. I have downloaded the samples and was actually able to add an invoice to my file with it, but I am a little confused. I have trouble connecting unless QB is up and running. I was trying to follow the code in the sample, but it is difficult. I need this app to add invoices and bills to the file even if QB is not open. They only have one file so there won't be an instance where another file is already open. Also, the environment is simple as everything runs on the same computer.

My basic questions are:

  1. How to select the correct QB file and provide credentials to allow access?
  2. Is there a decent simple example using QBFC? Everything I have found is using XML which seems overly complicated compared to QBFC.
  3. I cannot seem to get QB to open automatically. I have tried the code below and I get an error that states "Could not start QuickBooks".

Any pointers are greatly appreciated.

        QBSessionManager qbSession = new QBSessionManager();
        qbSession.OpenConnection("", "Lumber Management System");
        try
        {
            qbSession.BeginSession("C:\\Users\\Jerry\\Documents\\QuickBooks\\Company Files\\MRJ Tecnology, LLC", ENOpenMode.omDontCare);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + '\n' + ex.StackTrace, "Error opening QB");
        }
Jerry Welliver
  • 377
  • 1
  • 13

1 Answers1

1

There are a couple of things that you need in order for this to work. The first time that you request access to a company file, QuickBooks must be opened and the Admin must be logged in. The Admin will then be given a dialog to grant permission to your application to access QuickBooks. In the permission dialog, it will ask the Admin if they want to allow the application to read and modify the company file with four options:

  • No
  • Yes, prompt each time
  • Yes, whenever this QuickBooks company file is open
  • Yes, always; allow access even if QuickBooks is not running

The admin must choose the fourth option to allow your app to launch QuickBooks without running.

I would also suggest that you use OpenConnection2 instead of OpenConnection, and use a unique ID as the first parameter. You will also need to specify the connection type, which should be ENConnectionType.ctLocalQBD. It also appears that the filename you are passing in the BeginSession call does not include the .qbw extension. Here is a basic sample:

QBSessionManager SessionManager = null;
try
{
    SessionManager = new QBSessionManager();
    SessionManager.OpenConnection2("UniqueAppID", "Lumber Management System", ENConnectionType.ctLocalQBD);
    SessionManager.BeginSession("C:\\Users\\Jerry\\Documents\\QuickBooks\\Company Files\\MRJ Tecnology, LLC.qbw", ENOpenMode.omSingleUser);

    // CODE TO SEND TO QB GOES HERE
}
catch(Exception ex)
{
    MessageBox.Show("Error opening QB:" + ex.ToString());
}
finally
{
    if(SessionManager != null)
    {
        SessionManager.EndSession();
        SessionManager.CloseConnection();
    }
}
Hpjchobbes
  • 1,309
  • 1
  • 8
  • 11
  • Thanks for the response! I have seen these options in the documentation. 1) all of the documentation I have seen says the unique app id is only if the app is registered with Intuit and they give you the id. Should I just make one up? What does it buy me? 2) Does the ctLocalQBD connection type help with performance? Even on the local machine it seems to take several seconds to open the file and process - an eternity for a user staring at the screen. I have actually moved the file name to settings and it is working ok for now. I will look into the changes you suggest. – Jerry Welliver Jul 10 '18 at 18:39
  • From my understanding, the AppID doesn't really matter, I just add it as a habit. OpenConnection2 requires a connPref parameter. It doesn't make the performance better, as QB is still opening in the background, just not displaying the UI to the user. It does allow you to specify ctLocalQBDLaunchUI if you want to show the UI to the user, though. – Hpjchobbes Jul 11 '18 at 13:27