Connect SQL Server to SugarCRM
Use the SugarCRM ODBC Driver to connect Microsoft SQL Server to SugarCRM and:
- Use a linked server to work with SugarCRM data, just as if you were working with data stored in a SQL Server table.
- Integrate SugarCRM with SQL Server by using SQL Server Integration Services (SSIS).
Install and license the SugarCRM ODBC driver on the machine where SQL Server is installed.
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 SugarCRM ODBC Driver documentation.
Before you can use the SugarCRM ODBC Driver to connect SQL Server to SugarCRM, you need to configure an ODBC data source. An ODBC data source stores the connection details for the target database (e.g. SugarCRM) and the ODBC driver that is required to connect to it (e.g. the SugarCRM 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. Note that a User data source is only available to a SQL Server instance if that instance is run as a specific user, otherwise, you must use configure a System data source.
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:
If you have the 64-bit version of SQL Server and want to use a linked server with the SugarCRM ODBC driver, you need to run 64-bit version of ODBC Administrator. 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 or want to use SSIS with the SugarCRM ODBC driver, you need to run the 32-bit version of ODBC Administrator. To do this, in the Windows Run dialog box, type:
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 SugarCRM ODBC Driver data source:
Do one of the following:
To create a User data source, in the User DSN tab, choose Add.
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.
- To create a System data source, choose the System DSN tab, and then choose Add.
- To create a User data source, in the User DSN tab, choose Add.
- In the Create New Data Source dialog box, choose Easysoft ODBC-SugarCRM Driver, and then choose Finish.
Complete the Easysoft ODBC-SugarCRM Driver DSN Setup dialog box:
Setting Value DSN SugarCRM User Name The name of your SugarCRM user. For example, admin. Password The password for your SugarCRM user. Logon Uri The URI of the SugarCRM instance that you want to connect to. For example:
The Easysoft ODBC-SugarCRM Driver can connect to a SugarCRM instance both over
- Use the Test button to verify that you can successfully connect to SugarCRM.
You can now connect SQL Server to SugarCRM.
Example: Retrieve SugarCRM Data by using a Linked Server
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.
- Right-click Server Objects. From the pop-up menu choose New > Linked Server.
- In the Linked server box, type "SugarCRM".
- From the Provider list, choose Microsoft OLE DB Provider for ODBC Drivers.
In the Data source box, type the name of your SugarCRM ODBC data source, and then choose OK.
SQL Server verifies the linked server by testing the connection.
- If you get the error "Specified driver could not be loaded due to system error 126: The specified module could not be found", choose Yes when prompted whether to keep the linked server. You need to restart your SQL Server instance before you can use the linked server. If SQL Server was already running when you installed the SugarCRM ODBC driver, it will not have the latest version of the System PATH environment variable. The SugarCRM ODBC driver Setup program adds entries for the driver to the System PATH. Restarting the instance makes these changes available to SQL Server, allowing it to load the SugarCRM ODBC driver.
- If you made a mistake when specifying the SugarCRM ODBC data source, you get the error "Data source name not found and no default driver specified. If you get this error, choose No when prompted whether to keep the linked server and edit the value in the Data source box.
You can query your SugarCRM data either by using a:
Four part table name in a distributed query.
A four part table name has the format:
Even though with SugarCRM there is no database or schema, the Easysoft ODBC-SugarCRM 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
SUGAR. The schema that the driver returns is
DBO. Include thse identifiers in your SQL statements. For example:
SELECT * FROM SUGARCRM.SF.DBO.Accounts
The capitalisation of the table name must be the same as it is in SugarCRM. For example, the following query is invalid:
SELECT * FROM SUGARCRM.SF.DBO.ACCOUNTS
To check the capitalisation of the SugarCRM tables (objects), run:
EXEC sp_tables_ex @table_server = 'SUGARCRM'
Pass-through query in an OPENQUERY function. For example:
SELECT * FROM OPENQUERY(SUGARCRM, 'SELECT * FROM ACCOUNTS')
SQL Server sends pass-through queries as uninterpreted query strings to the SugarCRM 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.
- Four part table name in a distributed query.
Example: Retrieve SugarCRM Data by using OPENDATASOURCE / OPENROWSET
OPENROWSET functions enable you to work with SugarCRM 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.
In Microsoft SQL Server Management Studio, run these commands to enable the
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_SUGARCRM_ODBC_DATA_SOURCE;') .SF.DBO.Accounts
SELECT * FROM OPENROWSET('MSDASQL', 'DSN=MY_SUGARCRM_ODBC_DATA_SOURCE;', 'select * from Accounts;')
Example: Back Up a SugarCRM Table in SQL Server
This command creates a copy of the Account table, it assumes the linked server is named
IF OBJECT_ID('dbo.Account', 'U') IS NOT NULL DROP TABLE dbo.Accounts; SELECT * INTO Accounts FROM OPENQUERY(SUGARCRM,'SELECT * FROM Accounts')
These instructions assume that you have Microsoft Visual Studio and SQL Server Data Tools for Visual Studio installed.
Create a .csv file named categories.csv with the following contents:
name,is_external "Test Category 1",1 "Test Category 2",0
- In Visual Studio, create a new Integration Services Project.
- Drag a Data Flow Task from the Toolbox to the Control Flow tab.
- Choose the Data Flow tab.
Drag a Flat File Source from the Toolbox to the Data Flow tab, and then press Return.
Flat File Source is under the Other Sources list.
- In the Flat File Source Editor, choose New.
- In the Flat File Connection Manager Editor dialog box, browse for your .csv file.
- In the Text qualifier box, enter ".
- Choose Preview, and then choose OK to exit the dialog boxes.
Drag an ODBC Destination from the Toolbox to the Data Flow tab, and then press Return.
ODBC Destination is in the Other Destinations list.
- Select the Flat File Source. Drag the blue arrow over to the ODBC Destination.
- Select the ODBC Destination, and then press Return.
- In the ODBC Destination dialog box, choose New.
- In the Configure ODBC Connection Manager dialog box, choose New.
- In the Connection Manager dialog box, choose your SugarCRM ODBC data source, and then use the OK button to return to the ODBC Source dialog box.
- In the Name of the table or the view list, choose Product2.
- Choose Mappings.
Map the Name, Description and Family columns in the Input list to the same columns in the Destination list.
Your Input and Destination columns should look like this:
Input Column Destination Column [is_external] is_external name name
All other column names will have their input set to
- Choose the Start button to insert the records from the .csv file into SugarCRM.