Knowledgebase
[QODBC Desktop] How to Programmatically Retrieve the Current QuickBooks Company File from a QODBC Connection
Posted by William - QODBC Support on 28 September 2026 07:40 AM

[QODBC Desktop] How to Programmatically Retrieve the Current QuickBooks Company File from a QODBC Connection

Problem Description:

Developers connecting to QuickBooks data through QODBC via the ODBC API sometimes need to programmatically determine which QuickBooks company file is currently open and connected. This is useful for logging, audit trails, or dynamic report generation where the active company must be identified.

Affected products: QODBC Desktop, QRemote Server/Client, any ODBC client application (Excel VBA, MS Access, C#, Python, etc.)
Expected outcome: Retrieve the current QuickBooks company file path from the active QODBC connection using the DFQ parameter in the connection string.

Solution: Using SQLDriverConnect (ODBC API)

When connecting to QODBC via the ODBC API function SQLDriverConnect(), the driver returns the active connection string through the OutConnectionString output parameter. This connection string contains several parameters, including DFQ, which holds the full path of the current QuickBooks company file.

Example: VBA / MS Access

Dim conn As ADODB.Connection
Dim connString As String
Dim dfqValue As String

Set conn = New ADODB.Connection
conn.ConnectionString = "DSN=QuickBooks Data;DRIVER=QODBC;"
conn.Open

' Extract the DFQ parameter from the connection string'
dfqValue = conn.Properties(86)  ' Property index 86 returns DFQ'
MsgBox "Connected to: " & dfqValue

conn.Close

Example: C# / .NET

// Using ODBC API via P/Invoke
StringBuilder outConnStr = new StringBuilder(256);
// After calling SQLDriverConnect, scan outConnStr for DFQ=
string connStr = outConnStr.ToString();
// Parse the DFQ parameter from the connection string

Example: Python (pyodbc)

import pyodbc

conn = pyodbc.connect("DSN=QuickBooks Data")
# conn.cursor().description or connection.properties
# Access the DFQ parameter from the connection info

conn.close()

Understanding the QODBC Connection String Parameters

A QODBC connection string includes several key-value pairs. The most relevant ones are:

ParameterDescription
DSN System DSN name (e.g., "QuickBooks Data")
DFQ Current QuickBooks company file path https://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/2360 the value you want to retrieve
CDKEY Licensing information (masked or omitted for security)
DRIVER The ODBC driver name (e.g., "QODBC")

Note: QRemote Environments

In a QRemote setup, the DFQ parameter reflects the company file on the QODBC Server machine (where QuickBooks is running), not the client machine. If your application connects via QRemote, the DFQ value returned by SQLDriverConnect will still be valid - it tells you which QuickBooks company the remote server is currently connected to.

Example Scenarios:

Scenario 1 - Multi-company VBA application:

A financial analyst built an MS Access front-end that connects to QODBC. Before generating reports, the code checks the DFQ parameter from the connection string to log which company file was queried. This provides an audit trail of which data source was used for each report.

Scenario 2 - Debugging QRemote connections:

A developer troubleshooting a multi-VM QRemote setup needed to confirm which QuickBooks company file each server was serving. By reading the DFQ parameter from each connection, they verified that all VMs were pointing to the correct company files.

Keywords:

DFQ Parameter Connection String SQLDriverConnect Company File Path ODBC API QuickBooks Company VBA MS Access C# Python pyodbc QRemote
(0 vote(s))
Helpful
Not helpful

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