Knowledgebase: Connection
[QODBC-Desktop] Accessing QuickBooks Data remotely via SQL Server
Posted by Jack - QODBC Support on 19 August 2016 08:06 AM

Accessing QuickBooks Data remotely via SQL Server

First, you need to create Linked Server in SQL Server.

For 32-bit SQL Server. Please refer How to create Link Server with MS SQL 2005/2008/2012 32-bit Using QODBC/QRemote

For 64-bit SQL Server. Please refer How to create Link Server with MS SQL 2005/2008/2012 64-bit Using QODBC/QRemote

 

I have already created linked server "QRemote".

After creating Linked Server, You need to create a new database in SQL Server for creating the stored procedure which accepts SQL query, the stored procedure will call linked server and execute the query.

To create a database, You need to right-click on "Database" & click on "New Database".

Enter database name & click "OK". In this example, I am creating database "QODBC".

Database created.

Now, We will create a stored procedure which accepts SQL query, the stored procedure will call linked server and execute the query.

In Object Explorer, connect to an instance of Database Engine and then expand that instance.

Expand Databases, expand Your database, and then expand Programmability.

Right-click Stored Procedures, and then click New Stored Procedure.

 

We will create two stored procedure first one will give us a list of all customers & second procedure will accept SQL query through parameter & execute on linked server & provide the query result.

We will create the stored procedure named GetCustomer which will query Customer table through the linked table in SQL Server & provide a list of the customers.

Stored Procedure Created.

Stored Procedure Code:

================================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE GetCustomer

AS
BEGIN
SET NOCOUNT ON;

SELECT * from QRemote...customer

END
GO
================================================================

Note: The above-stored procedure code is for example. You can change it as per your requirement.

By executing this stored procedure we will get a list of the Customers.

We will create a second stored procedure named QODBCQuery which will accept SQL query through parameter & execute on linked server & provide the query result.

Stored Procedure Created.

Stored Procedure Code:

================================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

Create PROCEDURE QODBCQuery

@sqlQuery nvarchar( 4000)

AS
BEGIN
SET NOCOUNT ON;

DECLARE @TSQL varchar(8000)
SELECT @TSQL = 'SELECT * FROM OPENQUERY(QRemote,''' + @sqlQuery + ''')'
EXEC (@TSQL)

END
GO
================================================================

Note: The above stored procedure code is for example. You can change it as per your requirement.

To execute this stored procedure we need to pass query as the parameter value.

Query result through the stored procedure.



Now, We will create SQL Server DSN on the non-SQL Server machine to access QuickBooks Data remotely via SQL Server.

Locate the QODBC Driver for QuickBooks program group on your desktop. Click on the Configure QODBC Data Source icon to create SQL Server DSN.

Click on the System DSN tab to create a DSN that can be called by both Windows applications and services. Click on the Add button to create a new DSN.

Select SQL Server & click "Finish".

Enter DSN name, SQL Server machine IP address & click "Next".

Select authenticity of SQL Server & click "Next".

Select SQL Server database in which we have created stored procedure & click "Next".

Click "Finish".

Click on "Test Data Source.." to test the connection.

Test connection success.



Now we will call this stored procedure from QDemo application. We will use connection string "DSN=SQL;Uid=sa;Pwd=sa;" & click on Test Connection.
Note: You need to change DSN Name & User ID & Password as per your configuration.

Note: I have used QDemo application for testing purpose only. You can use your application (i.e. MS Access, Excel, VBA etc..) as per your requirement.

Now we will call stored procedure GetCustomer from QDemo application. Write stored procedure name (i.e. GetCustomer) & click on "Run Query".

By executing this stored procedure we will get a list of the Customers.

Now we will call second stored procedure QODBCQuery from QDemo application. To execute this stored procedure we need to pass query as the parameter value.

Write stored procedure name & query as parameter(i.e. QODBCQuery 'select * from account where name like ''''te%'''' ') & click on "Run Query".

Note: You need to pass four single quotes around string value after where condition.

Query result through the stored procedure.

 

(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).