Ready to get started?

Learn more about Sage US Connectivity Solutions

Learn More

Connect to Sage US as an External Data Source using PolyBase

Use the CData ODBC Driver for Sage US and PolyBase to create an external data source in SQL Server 2019 with access to live Sage US data.

PolyBase for SQL Server allows you to query external data by using the same Transact-SQL syntax used to query a database table. When paired with the CData ODBC Driver for Sage US, you get access to your Sage US data directly alongside your SQL Server data. This article walks through creating an external data source and external tables to grant access to live Sage US data using T-SQL queries.

The CData ODBC drivers offer unmatched performance for interacting with live Sage US data using PolyBase due to optimized data processing built into the driver. When you issue complex SQL queries from SQL Server to Sage US, the driver pushes down supported SQL operations, like filters and aggregations, directly to Sage US and utilizes the embedded SQL engine to process unsupported operations (often SQL functions and JOIN operations) client-side. And with PolyBase, you can also join SQL Server data with Sage US data, using a single query to pull data from distributed sources.

Connect to Sage US

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs. To create an external data source in SQL Server using PolyBase, configure a System DSN (CData Sage US Sys is created automatically).

The Application Id and Company Name connection string options are required to connect to Sage as a data source. You can obtain an Application Id by contacting Sage directly to request access to the Sage 50 SDK.

Sage must be installed on the machine. The Sage.Peachtree.API.dll and Sage.Peachtree.API.Resolver.dll assemblies are required. These assemblies are installed with Sage in C:\Program Files\Sage\Peachtree\API\. Additionally, the Sage SDK requires .NET Framework 4.0 and is only compatible with 32-bit applications. To use the Sage SDK in Visual Studio, set the Platform Target property to "x86" in Project -> Properties -> Build.

You must authorize the application to access company data: To authorize your application to access Sage, restart the Sage application, open the company you want to access, and connect with your application. You will then be prompted to set access permissions for the application in the resulting dialog.

While the compiled executable will require authorization only once, during development you may need to follow this process to reauthorize a new build. To avoid restarting the Sage application when developing with Visual Studio, click Build -> Configuration Manager and uncheck "Build" for your project.

Click "Test Connection" to ensure that the DSN is connected to Sage US properly. Navigate to the Tables tab to review the table definitions for Sage US.

Create an External Data Source for Sage US Data

After configuring the connection, you need to create a master encryption key and a credential database for the external data source.

Creating a Master Encryption Key

Execute the following SQL command to create a new master key, 'ENCRYPTION,' to encrypt the credentials for the external data source.

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password';

Creating a Credential Database

Execute the following SQL command to create credentials for the external data source connected to Sage US data.

NOTE: Since Sage US does not require a User or Password to authenticate, you may use whatever values you wish for IDENTITY and SECRET.

CREATE DATABASE SCOPED CREDENTIAL sage50us_creds
WITH IDENTITY = 'username', SECRET = 'password';

Create an External Data Source for Sage US

Execute the following SQL command to create an external data source for Sage US with PolyBase, using the DSN and credentials configured earlier.

For Sage US, set SERVERNAME to 'localhost' or '127.0.0.1' and leave PORT empty. PUSHDOWN is set to ON by default, meaning the ODBC Driver can leverage server-side processing for complex queries.

CREATE EXTERNAL DATA SOURCE cdata_sage50us_source
WITH ( 
  LOCATION = 'odbc://SERVERNAME[:PORT]',
  CONNECTION_OPTIONS = 'DSN=CData Sage US Sys',
  -- PUSHDOWN = ON | OFF,
  CREDENTIAL = sage50us_creds
);

Create External Tables for Sage US

After creating the external data source, use CREATE EXTERNAL TABLE statements to link to Sage US data from your SQL Server instance. The table column definitions must match those exposed by the CData ODBC Driver for Sage US. You can refer to the Tables tab of the DSN Configuration Wizard to see the table definition.

Sample CREATE TABLE Statement

The statement to create an external table based on a Sage US Customer would look similar to the following:

CREATE EXTERNAL TABLE Customer(
  Name [nvarchar](255) NULL,
  LastInvoiceAmount [nvarchar](255) NULL,
  ...
) WITH ( 
  LOCATION='Customer',
  DATA_SOURCE=cdata_sage50us_source
);

Having created external tables for Sage US in your SQL Server instance, you are now able to query local and remote data simultaneously. Thanks to built-in query processing in the CData ODBC Driver, you know that as much query processing as possible is being pushed to Sage US, freeing up local resources and computing power. Download a free, 30-day trial of the ODBC Driver for Sage US and start working with live Sage US data alongside your SQL Server data today.