Salesforce SOQL from SQL Server

The Salesforce ODBC Driver extends the number of applications that you can use Salesforce SOQL from. In this blog, we describe how to run SOQL statements from SQL Server.

To get started:

Before you can use the ODBC Driver to connect your application to, you need to configure an ODBC data source. An ODBC data source stores the connection details for the target database (e.g. and the ODBC driver that is required to connect to it (e.g. the ODBC driver).

If you have the 64-bit version of SQL Server, you need to run 64-bit version of ODBC Administrator (which you use to create a data source). To do this, open Administrative Tools in Control Panel, and then open Data Sources ODBC. On Windows Server 2003 and earlier, the Control Panel applet that launches ODBC Administrator is labelled Data Sources. On Windows 8 and later, the Control Panel applet is labelled ODBC Data Sources (64-bit).)

If you have the 32-bit version of SQL Server, you need to run 32-bit version of ODBC Administrator. To do this, in the Windows Run dialog box, type:


To create a ODBC Driver data source:

  1. In the ODBC Administrator, choose the System DSN tab, and then choose Add.

    To run the 32-bit version of ODBC Administrator, in the Windows Run dialog box, enter:

  2. In the Create New Data Source dialog box, choose Easysoft Salesforce SOQL ODBC Driver, and then choose Finish.
  3. Complete the Easysoft Salesforce SOQL ODBC Driver DSN Setup dialog box:
    Setting Value
    User Name The name of your user. For example,
    Password The password for your user.
    Token The security token for your user, if required.

    To find out whether you need to supply a security token, choose the Test button. If the connection attempt fails with an error which contains LOGIN_MUST_USE_SECURITY_TOKEN, you need to supply one. emails the security token to the email address associated with your user account. If you have not received a security token, you can regenerate it. will then email the new security token to you. To regenerate your security token, log in to and then choose Setup from the user menu. Search for "security token" in the Quick Find box. Click Reset Security Token in the Reset Security Token page. When you receive the token in your email client, copy it and then paste it into the Token field.

  4. Use the Test button to verify that you can successfully connect to

Using Salesforce SOQL from SQL Server

Using the Salesforce ODBC driver to access Salesforce data from SQL Server:

  1. In Microsoft SQL Server Management Studio, connect to the SQL Server instance you want to create the linked server against.

    You need to log on with an account that is a member of the SQL Server sysadmin fixed server role to create a linked server.

  2. Right-click Server Objects. From the pop-up menu choose New > Linked Server.
  3. In the Linked server box, type "Salesforce".

    (If you want to call the Linked server "", you will have to enclose this name in double quotes in your SQL statements. For example, SELECT * FROM "SALESFORCE.COM"...Account.)

  4. From the Provider list, choose Microsoft OLE DB Provider for ODBC Drivers.
  5. In the Data source box, type the name of your ODBC data source, and then choose OK.

    SQL Server verifies the linked server by testing the connection.

  6. You can query your data by using a pass-through SQL Query. For example:
    SELECT * FROM OPENQUERY(SALESFORCE,'SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts) FROM Account')
    EXEC ('SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts) FROM Account' ) at SALESFORCE