Knowledgebase
[QODBC-Desktop] I'm getting the error message "Cannot close company file" / Getting "Cannot close QuickBooks" message from QuickBooks after closing my application.
Posted by Wilson (QODBC Support) on 08 May 2012 07:34 AM

Troubleshooting: Getting a "Cannot close QuickBooks" message from QuickBooks after closing my application.

Problem Description 1:

Using QODBC with your application, always get the "Cannot close QuickBooks" message after closing the application.

Solutions 1: 

The cause of the issue is connection was not closed by your application.

Please make sure your application is sending the disconnect command to QODBC. 

If you use Microsoft Access, please close the MS Access application to disconnect the connection. MS Access will keep the connection open until the application is closed.

 

If you have killed/aborted any process, this means QODBC and QuickBooks have not received the disconnect command. QuickBooks will still have the connection flag ON.

 

You could manually close QuickBooks via Windows Task Manager. Click Ctrl+Alt+Del to open the task manager, switch to the Processes window, and locate and terminate the QBW32.EXE process to close QuickBooks.

 

 

 

Solutions 2: 

Please check your code to see if you have added code to close and dispose of the connection.

In case you are using OdbcDataReader ( Please make sure you always call Close before you dispose of the object.).

Here is an example of a VBS code:

Const adOpenStatic = 3
Const adLockOptimistic = 3

Dim oConnection
Dim oRecordset
Dim sMsg
Dim sConnectString
Dim sSQL

sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "SELECT Name FROM Employee"
Set oConnection = CreateObject("ADODB.Connection")
Set oRecordset = CreateObject("ADODB.Recordset")

oConnection.Open sConnectString
oRecordset.Open sSQL, oConnection, adOpenStatic, adLockOptimistic
sMsg = "**********************" & Chr(10)
Do While (not oRecordset.EOF)
sMsg = sMsg & oRecordSet.Fields("Name") & Chr(10)
oRecordset.MoveNext
Loop
sMsg = sMsg & "**********************" & Chr(10)
MsgBox sMsg

oRecordset.Close
Set oRecordset = Nothing
oConnection.Close
Set oConnection = Nothing

Please notice the final part we use this:

oRecordset.Close
Set oRecordset = Nothing
oConnection.Close
Set oConnection = Nothing

To close the connection.

And we also kindly suggest you make sure all the connection references are in Data Readers or other objects where the connection is used.

 

Problem Description 2:

I use Microsoft Access 2010 and QODBC to pull data out of Reckon Accounts. If I link a table with Reckon accounts, I get the message, "The company file cannot be closed at this time because there is another application (addin product or background task) that is using it. Before closing the company file, you must either close that application or instruct the application to end its session with Reckon Accounts". This happens despite MS Access being already closed. 

 

http://support.flexquarters.com/esupport/newimages/Cannotclosecompanyfile/step1.png

 
I have the 'Force close Quickbooks' setting already enabled, but it resulted in Quickbooks closing suddenly about 10 minutes after Access / QODBC were used.

 

Solution 3:

The problem is only due to linking a file to the Reckon account via QODBC. 

Ms. Access would not be releasing the connection. Please make sure you are closing the connection. If the Table/Query is open (i.e., displaying the result ), you may not be able to close the company file.


Close the data set view and then try again.

If you still face the issue, Close MS Access and try again.

If you are working with multiple company files, I suggest you add a 5-10 seconds gap between closing and opening the connection to another company. QuickBooks require this time to close the existing company file and make the application available to load another company file.

 

Additional Information for Service/Task Manager based applications


When the Disconnect command is sent to QODBC, QODBC sends the same to
QuickBooks SDK and SDK close Company files and QuickBooks. Many times QuickBooks (QBW32.exe) does not close when using SDK via a Service/Task Manager-based application
I would suggest trying the below Options and see if that helps
1) Make sure you un-select the option of "Keep QuickBooks running for
quick start-up" under QuickBooks -- Edit Preferences -- General.
Close all other QuickBooks instances of all other users and then try.
(Please verify no instances are running of QBW32 under the task manager
--processes -- view all user processes)
OR
2) For QODBC 13.0.0.291 and upwards, under the Advance tab, enable "Force
Close QuickBooks". Also, make sure you un-select the option of "Keep
QuickBooks running for quick start-up" under QuickBooks -- Edit
Preferences -- General
(QuickBooks shall be closed on each Disconnect command )


If the above does not work for you, you may have to write code to Close QuickBooks after the company file is closed.

 

Tag: QuickBooks does not close when an application is turned off. The company file cannot be closed, unable to close the company file.

(2 vote(s))
Helpful
Not helpful

Comments (4)
Gordon Jennings
02 June 2015 10:21 PM
I get this error on my QuickBooks machine (running QRemote Server) after testing SQL queries using the supplied VB Demo application on a remote machine running QRemote Server. Nothing I've written.
Jack
04 June 2015 01:47 PM
Hi Gordon,

There might be some active connection between QODBC & QuickBooks, due to this you are getting this error. You need to close all active connection between QODBC & QuickBooks to close QuickBooks company file.
Colt
12 September 2017 03:10 PM
"oConnection.Open sConnectString
oRecordset.Open sSQL, oConnection, adOpenStatic, adLockOptimistic
sMsg = "**********************" & Chr(10)
Do While (not oRecordset.EOF)
sMsg = sMsg & oRecordSet.Fields("Name") & Chr(10)
oRecordset.MoveNext
Loop
sMsg = sMsg & "**********************" & Chr(10)
MsgBox sMsg "

During this bit of code, how would I do an import of a table without establishing a new connection.
Right now I use the command TransferDatabase acimport, "ODBC Database", "ODBC; DSN Quickbooks Data; DFQ=C: \Users ... This creates it's own connection separate to your code. How do I close that connection from an import OR how do I incorporate an import into your code?

It's imperative that I get this done because I need Quickbooks to be accessible because of the single-user mode. If there is anything you can help with then please do.

Thanks!
Jack
13 September 2017 01:37 PM
Hi Colt,

I would like to share that when you use DoCmd, MS Access keeps the connection open & due to this QuickBooks Company file can't close until MS Access database is closed. MS Access will close connection to QuickBooks after closing MS Access.

So you need to close MS Access, then try to close company.

If you are still facing the issue, Please raise a support ticket to the QODBC Technical Support department from below mentioned link & provide requested information:
http://support.flexquarters.com/esupport/index.php?/Tickets/Submit

We may need the following information, Please attach below listed files when replying to the ticket.
1) Screenshot of QODBC Setup Screen -- > About
2) Screenshot of the issue you’re facing.
Share Entire Log Files as an attachment in text format from
3) QODBC Setup Screen -- > Messages -- > Review QODBC Messages
4) QODBC Setup Screen -- > Messages -- > Review SDK Messages

Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please complete the captcha below (we use this to prevent automated submissions).