How to query NetSuite from SQL Server with an ODBC data source and a linked server

Read the SuiteAnalytics Connect values, configure a 64-bit System DSN and test it, then add a SQL Server linked server and query a NetSuite table from Management Studio.

The quick answer

Copy the Service Host, Account ID and Role ID from Your Configuration on the Set Up SuiteAnalytics Connect page. On the SQL Server machine, open the 64-bit ODBC Data Source Administrator, select the NetSuite entry on the System DSN tab, click Configure, enter those values and run Test Connect. Then, in SQL Server Management Studio, create a linked server with the Microsoft OLE DB Provider for ODBC Drivers, use the DSN name as its Data source and map logins to your NetSuite email and password. Expand the linked server to see the NetSuite tables and query one.

Inline images show the field or area used in each step. Select Enlarge to see the complete recorded screen and its surrounding context.

The example is a wholesale company whose reporting analyst wants to join NetSuite records with data that already lives in SQL Server. The screenshots use sample data, and the person and company names are fictional. The ODBC Administrator and SQL Server Management Studio screens are generic stand-ins built from a 2019 walkthrough, so your Windows and SSMS versions will look a little different, and the SuiteAnalytics Connect page layout may differ in your account.

Before you start

SuiteAnalytics Connect is a separately provisioned, read-only service. Check with your NetSuite administrator that it is provisioned for your account. Some accounts also list a SuiteAnalytics Connect feature under Setup > Company > Enable Features on the Analytics subtab, which should be on where it is listed. The role you connect with needs the SuiteAnalytics Connect permission, has to be available to the employee whose credentials the DSN uses (check that employee's Access tab), and still needs ordinary permissions for the records and fields you want to read, within its subsidiary and other restrictions. Connect access does not by itself open every table. A dedicated integration employee and a least-privilege role are safer than Administrator or personal credentials.

Install the latest SuiteAnalytics Connect ODBC driver for your operating system on the machine that runs the SQL Server service, not only on your own PC, and match the driver to SQL Server: a 64-bit SQL Server needs the 64-bit driver and the 64-bit ODBC Data Source Administrator. Management Studio's own bitness does not matter, because the SQL Server service opens the connection. Use a System DSN so the service can see it. If the driver installer created a starting DSN, as in this example, you configure that one. Otherwise click Add and choose the installed driver. This guide is for SQL Server on Windows, and the SQL Server machine must be able to reach the Service Host on TCP port 1708.

A username and password sign-in is not available for a role or user that requires an interactive two-factor challenge the ODBC flow cannot complete. Use an authentication method the driver and account support, such as token-based or OAuth-based authentication where applicable. That changes the credential values you enter in the logon dialog and on the Security page. For a username and password login, SQL Server stores the password, so use a dedicated, restricted NetSuite user and a rotation process.

01. Read the connection values

On Home, click Set Up SuiteAnalytics Connect in the Settings portlet. The Drivers list includes the ODBC Driver 64-bit and ODBC Driver 32-bit; a 64-bit SQL Server needs the 64-bit one. Click Your Configuration and note Service Host 4827361.connect.api.netsuite.com, Service Port 1708, Service Data Source NetSuite2.com, Account ID 4827361 and Role ID 1047. Copy them from the page instead of inferring the host from the account ID. The host can differ between production, sandbox and Release Preview accounts.

Your Configuration holds the five values the DSN needs.

02. Open the 64-bit ODBC Administrator

On the SQL Server machine, open the ODBC Data Source Administrator (64-bit). The 32-bit administrator is a different program and lists different data sources. Select the System DSN tab. The installer's data source, NetSuite, is listed as 64-bit with the driver NetSuite Drivers 64bit. The data source name and the driver label can differ by driver version, so read them from your own list. Select it and click Configure.

The System DSN tab lists the 64-bit NetSuite data source.

03. Enter the values in the driver setup

The SuiteAnalytics Connect ODBC Driver Setup opens on the General tab with the installer's defaults: a placeholder Service Host, Service Port 1708 and the Service Data Source. Change Name to NetSuite Reporting. The Name is the DSN name, which is separate from the Service Data Source value NetSuite2.com. The linked server has to use this exact DSN name later. Replace Service Host with 4827361.connect.api.netsuite.com, then enter Account ID 4827361 and Role ID 1047. Leave Service Port 1708 and Service Data Source NetSuite2.com as they are. This walkthrough does not open the Security and About tabs. The Security tab holds connection-security settings such as encryption and certificate trust. Keep the driver's current defaults, and never disable certificate validation to get a connection working.

The host, Account ID and Role ID must match Your Configuration exactly.

04. Test Connect and save the DSN

Click Test Connect. A logon dialog asks for a user name and password and, here, also shows the Account ID and Role ID from the setup. Enter the NetSuite email priya.ramanathan@lakeshore.example and its password, then click OK. The driver reports Connection successful. That wording is an example and varies by driver version. This proves the driver, host, credentials and role. It does not yet prove that SQL Server can see the DSN or that the linked server works. Click OK on the message, then OK in the driver setup and in the administrator, as your version requires, and the System DSN is saved under the name NetSuite Reporting. If the test fails, recheck the host, Account ID, Role ID and password before you touch SQL Server.

Test Connect reports Connection successful for the new DSN.

05. Define the linked server

In SQL Server Management Studio, connected to the SQL Server instance, expand Server Objects, right-click Linked Servers and choose New Linked Server. On the General page enter the Linked server name NS_REPORTING and choose Server type Other data source. Choose the Microsoft OLE DB Provider for ODBC Drivers, enter a descriptive Product name, here NetSuite, and enter Data source NetSuite Reporting, which must match the System DSN name exactly. Product name is only a label. This walkthrough leaves Provider string, Location and Catalog blank. Some environments need the Provider string set to DSN=NetSuite Reporting, the exact Windows DSN name, never DSN=NetSuite2.com.

Data source is the System DSN name, typed exactly as saved.

06. Map the NetSuite login

Select the Security page. The list of local logins stays empty. Under For a login not defined in the list above, connections will, choose Be made using this security context. Enter the NetSuite email as Remote login and its password under With password, then click OK. A Windows or SQL Server login does not exist in NetSuite, so a fixed remote login is how the linked server signs in. For a username and password login, SQL Server stores that password, so use a dedicated, restricted NetSuite user, limit who can administer linked servers and rotate the credential. Token-based and OAuth methods use different values.

The fixed remote login is the NetSuite email, with its password stored by SQL Server.

07. Find the NetSuite tables

The new linked server appears under Linked Servers. Expand NS_REPORTING, then Catalogs. The Lakeshore Wholesale Co. catalog is listed beside System Catalogs. Expand it and Tables to see the SuiteAnalytics Connect tables, each listed with a prefix, BI Connect Reader in this example. If the tree is empty, refresh it. The role and the Service Data Source decide which tables appear. The catalog and prefix names vary by driver version and configuration, so copy them from Object Explorer instead of inferring them from the role name.

The catalog and its Tables are listed under the linked server.

08. Query a NetSuite table

Click New Query and enter select * from [NS_REPORTING].[Lakeshore Wholesale Co.].[BI Connect Reader].[ACCOUNTS], a four-part name made of the linked server, catalog, prefix and table, each in brackets. Click Execute. The Results grid lists the NetSuite account records with columns such as ACCOUNTNUMBER, ACCOUNT_ID, CASHFLOW_RATE_TYPE and DATE_LAST_MODIFIED, and the status bar reports Query executed successfully with 41 rows. Here the four-part name runs. SQL Server parses it first, so with this provider it can fail even when Object Explorer lists the table. OPENQUERY sends the SQL text straight to the driver as pass-through SQL and is often more predictable, for example SELECT * FROM OPENQUERY(NS_REPORTING, 'SELECT * FROM ACCOUNTS'), using a table name that Object Explorer actually lists. For a repeated report, name the columns you need and put filters inside the OPENQUERY text. The connection is read-only, so it supports SELECT and cannot change NetSuite records.

The ACCOUNTS table returns 41 rows through the linked server.

If the DSN passes Test Connect but the linked server fails, check in this order: the DSN is a 64-bit System DSN on the SQL Server machine, the SQL Server service can load the driver, its name equals the linked server's Data source, the remote login and password on the Security page, and the options of the MSDASQL provider under Server Objects > Linked Servers > Providers. Allow inprocess is not a general requirement. Some SQL Server and provider combinations need it, so try it only as an environment-specific step under your change control. For a repeating report, SQL Server may not push filters and joins down to NetSuite efficiently, so extract the rows into a SQL Server table instead of relying on a live join.

Common questions

How do I connect SQL Server Management Studio to NetSuite?

Install the SuiteAnalytics Connect ODBC driver on the SQL Server machine, create a System DSN with your Service Host, Account ID and Role ID, and test it with Test Connect. Then create a linked server in SSMS that uses the Microsoft OLE DB Provider for ODBC Drivers and the DSN name as its Data source, with a fixed NetSuite login on the Security page.

Should I use the 32-bit or 64-bit ODBC driver?

Match the process that loads the driver. The SQL Server service opens a linked server connection, not Management Studio, so a 64-bit SQL Server needs the 64-bit driver and a DSN made in the 64-bit ODBC Data Source Administrator. A DSN made in the 32-bit administrator is not visible to a 64-bit process.

Why does the DSN need to be a System DSN?

A System DSN is visible to every user and service on the machine, including the SQL Server service. A User DSN belongs to the Windows user who created it, so the service often cannot use it. Create the DSN on the SQL Server machine itself.

What goes in the Service Host, Service Port and Service Data Source fields?

Copy the Service Host from Your Configuration on the Set Up SuiteAnalytics Connect page. Use port 1708 and, for new connections, NetSuite2.com, and compare them with the page. Your Configuration also shows the Account ID and Role ID. The host can differ between production, sandbox and Release Preview accounts, so do not infer it from the account ID.

Is the DSN name the same as the Service Data Source?

No. The DSN name is the Name you give the data source in the ODBC Administrator, and the linked server's Data source must match it. The Service Data Source, normally NetSuite2.com, is a separate value inside the DSN that tells the driver which NetSuite data source to use.