How to Connect to Quickbooks Desktop with ODBC using Microsoft SQL Server - chadbuildsthings/qbd-db-research GitHub Wiki
Prerequisites
- Quickbooks Desktop (tested with Quickbooks Desktop for Enterprise 24)
- Microsoft SQL Server Standard or higher installed (tested with 2019 Standard)
- Microsoft SQL Server Management Studio installed (tested with version 20)
- A SQL Server user created to log in with
- A Quickbooks Desktop user to log in with
Creating a Connection String
To set up a Linked Server that is connected to Quickbooks, we have to use a Provider String that is 32 characters or less.
- The provider string has 2 components, each of which count towards this 32 character limit
- FILEDSN=
- The path to the connection file located in your quickbooks directory
- Therefore we only have 24 characters to use for our file path.
- There are also some caveats
- Any \ character must be replaced with the characters \\
- If you have any spaces in your path, you must enclose the entire path with double quotes, which also count towards the limit
- You cannot use a UNC path (Note: A mapped drive might work, but I haven’t tested this)
- There are a few things that can be done to get this file dsn path character count down
- Make sure your server name is as short as possible (e.g. QBE)
- Create an NTFS junction in C:\ (e.g. C:\QB) to point to C:\Users\Public\Intuit\Quickbooks\Company files
- From cmd or powershell, issue this example command:
mklink /J C:\\QB C:\\Users\\Public\\Intuit\\Quickbooks\\Company files
- From cmd or powershell, issue this example command:
- Rename your company data file to be a single letter with .qbw extension. To do this, follow these steps.
- Log everyone out of Quickbooks
- Close Quickbooks
- Go to your company data directory in File Explorer (e.g. C:\Users\Public\Intuit\Quickbooks\Company files or C:\QB)
- Make sure you can see file extensions in File Explorer
- Click View tab
- Make sure File Name extensions is checked
- Find your company data file. It will have a .qbw extension
- Right click on it and click Rename
- Make it a single letter and .qbw (e.g. s.qbw)
- Double click it to open Quickbooks
- Verify in file explorer that there now exists a file named the same way as your new company data file, but with a .dsn extension (e.g. s.qbw.DSN)
- Make sure to go to all computers (workstations and remote desktop session hosts) that access this company file and reopen it. This will ensure the next time a user logs in, they can access your company’s data file without having to browse for it.
- Now we should be able to have a provider string 32 characters or less (e.g. FILEDSN=C:\QB\s.qbw.DSN is only 23 characters)
Creating an ODBC User
- Log in to Quickbooks using the admin account
- Go to Reports > Custom Reports > ODBC
- Click “Manage ODBC Users”
- Click New…
- Give an ODBC User Name
- Create a password. (Note I had issues using symbols)
- Confirm password
- Click QBReportAdminGroup
- Click Add >>
- Click OK
Create a Linked Server
- Open SQL Server Management Studio
- In the Object Explorer, expand your SQL Server Instance
- Expand Server Objects
- Right Click Linked Servers
- Click “New Linked Server”
- In the General page
- Give it a Linked Server name (e.g. QB_LINK)
- Tick “Other data Source”
- Use provider string generated from the first section (e.g. FILEDSN=C:\QB\s.qbw.dsn)
- In the Security page
- Tick “Be made using this security context:”
- Remote login: enter ODBC User Name from Quickbooks
- With password: enter ODBC Password from Quickbooks
- Tick “Be made using this security context:”
- Click OK. There shouldn’t be any errors.
- Verify that it worked
- Assuming you named your linked server QB_Link
- Click New Query
- Enter the following command and click execute:
SELECT * FROM OPENQUERY([QB_LINK], ‘SELECT DB_NAME() AS CurrentDatabase’);
- A result should appear with column header “Current Database” and row 1 value being a long string of numbers and letters ranging from a through f
- If you get a result like this, it worked.