|
[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 ConnectionProblem 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.) Solution: Using SQLDriverConnect (ODBC API)When connecting to QODBC via the ODBC API function Example: VBA / MS AccessDim 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 ParametersA QODBC connection string includes several key-value pairs. The most relevant ones are:
Note: QRemote EnvironmentsIn 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. Related Resources:
Keywords:DFQ Parameter Connection String SQLDriverConnect Company File Path ODBC API QuickBooks Company VBA MS Access C# Python pyodbc QRemote
| |||||||||||
|
|
|||||||||||


