New! Our optimal solution for working with Salesforce data by using Transact-SQL (T-SQL) is now available.
New! The Salesforce ODBC driver now includes two ODBC drivers, one which supports SQL and one which supports SOQL. This article is for the SQL version of the driver (Easysoft Salesforce ODBC Driver). For the SOQL version of the driver please refer to this blog.
Use the Salesforce.com ODBC Driver to connect Microsoft SQL Server to Salesforce.com and:
The Salesforce.com ODBC Driver is available to download from the Easysoft web site:
Note If you want to use the linked server in a clustered environment, you need to install the ODBC Driver on each node in the cluster.
For installation instructions, see the Salesforce.com ODBC Driver documentation.
Before you can use the Salesforce.com ODBC Driver to connect SQL Server to Salesforce.com, you need to configure an ODBC data source. An ODBC data source stores the connection details for the target database (e.g. Salesforce.com) and the ODBC driver that is required to connect to it (e.g. the Salesforce.com ODBC driver).
Note If you want to use the linked server in a clustered environment, you need to configure the data source on each node in the cluster.
You can configure a User ODBC data source, which is only available to the user who creates it, or a System ODBC data source, which is available to all users on the machine. You configure ODBC data sources in ODBC Administrator, which is included with Windows.
64-bit Windows There are two versions of ODBC Administrator on this platform. (If you are not sure whether your version of Windows is 32-bit or 64-bit, follow the instructions in this Microsoft Knowledge Base article to find out.) The version of ODBC Administrator that you need to run depends on whether you have a 32-bit or a 64-bit version of SQL Server. To find out which version of SQL Server you have, connect to your SQL Server instance, and then run this SQL statement:
select SERVERPROPERTY('edition')
If you have the 64-bit version of SQL Server and want to use a linked server with the Salesforce.com ODBC driver, you need to run the 64-bit version of ODBC Administrator. To do this, open Administrative Tools in Control Panel, and then open ODBC Data Sources (64-bit). (On Windows Server 2003 and earlier, the Control Panel applet that launches ODBC Administrator is labelled Data Sources.)
If you have the 32-bit version of SQL Server or want to use SSIS with the Salesforce.com ODBC driver, you need to run the 32-bit version of ODBC Administrator. To do this, in the Windows Run dialog box, type:
%windir%\syswow64\odbcad32.exe
32-bit Windows To run ODBC Administrator on 32-bit Windows, open Administrative Tools in Control Panel, and then open Data Sources (ODBC). (On older versions of Windows, the Control Panel applet that launches ODBC Administrator is labelled Data Sources.)
Use ODBC Administrator to create your Salesforce.com ODBC Driver data source:
Important This will only succeed if the SQL Server instance is running under the same user account as the one used to create the data source. Otherwise, you must create a System ODBC data source instead.
–Or–
Setting | Value |
---|---|
DSN | Salesforce.com |
User Name | The name of your Salesforce.com user. For example, myuser@mydomain.com. |
Password | The password for your Salesforce.com user. |
Token |
The security token for your Salesforce.com 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 Salesforce.com emails the security token to the email address associated with your Salesforce.com user account. If you have not received a security token, you can regenerate it. Salesforce.com will then email the new security token to you. To regenerate your security token, log in to Salesforce.com 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. |
You can now connect SQL Server to Salesforce.com.
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.
(If you want to call the Linked server "Salesforce.com", you will have to enclose this name in double quotes in your SQL statements. For example, SELECT * FROM "SALESFORCE.COM"...Account
.)
SQL Server verifies the linked server by testing the connection.
A four part table name has the format:
server_name.[database_name].[schema_name].table_name.
Even though with Salesforce.com there is no database or schema, the Easysoft ODBC-Salesforce Driver returns a "dummy" value for both identifiers, because some ODBC applications expect there to be a database and a schema. The database that the driver returns is SF
. The schema that the driver returns is DBO
. Include these identifiers in your SQL statements. For example:
SELECT * FROM SALESFORCE.SF.DBO.Account
The capitalisation of the table name must be the same as it is in Salesforce.com. For example, the following query is invalid:
SELECT * FROM SALESFORCE.SF.DBO.ACCOUNT
To check the capitalisation of the Salesforce.com tables (objects), run:
EXEC sp_tables_ex @table_server = 'SALESFORCE'
SELECT * FROM OPENQUERY(SALESFORCE, 'SELECT * FROM ACCOUNT')
SQL Server sends pass-through queries as uninterpreted query strings to the Salesforce.com ODBC driver. This means that SQL Server does not apply any kind of logic to the query or try to estimate what that query will do.
The OPENDATASOURCE
/ OPENROWSET
functions enable you to work with Salesforce.com data in SQL Server without configuring a linked server. There are some security implications associated with their use and these functions are therefore not enabled by default.
OPENDATASOURCE
/ OPENROWSET
functions:
EXEC sp_configure 'show advanced options', 1 RECONFIGURE GO EXEC sp_configure 'ad hoc distributed queries', 1 RECONFIGURE GO
SELECT * FROM OPENDATASOURCE('MSDASQL', 'DSN=MY_SALESFORCE_ODBC_DATA_SOURCE;') .SF.DBO.Account
—Or—
SELECT * FROM OPENROWSET('MSDASQL', 'DSN=MY_SALESFORCE_ODBC_DATA_SOURCE;', 'select * from Account;')
This command creates a copy of the Account table, it assumes the linked server is named SALESFORCE
.
IF OBJECT_ID('dbo.Account', 'U') IS NOT NULL DROP TABLE dbo.Account; SELECT * INTO Account FROM OPENQUERY(SALESFORCE,'SELECT * FROM Account')
These instructions assume that you have Microsoft Visual Studio and SQL Server Data Tools for Visual Studio installed.
Name,Description,Family Easysoft ODBC-Salesforce Driver,"ODBC Driver for Salesforce.com, Force.com, Database.com",Easysoft Data Access Easysoft ODBC-SQL Server Driver,"ODBC Driver for SQL Server, SQL Azure",Easysoft Data Access
Flat File Source is under the Other Sources list.
ODBC Destination is in the Other Destinations list.
Your Input and Destination columns should look like this:
Input Column | Destination Column |
---|---|
Name | Name |
<ignore> | ProductCode |
Description | Description |
<ignore> | IsActive |
<ignore> | CreatedDate |
<ignore> | CreatedById |
<ignore> | LastModifiedDate |
<ignore> | LastModifiedById |
<ignore> | SystemModstamp |
Family | Family |