Create a Linked Server
This section describes how to configure and create a linked SQL Server instance.
Configure the Provider Options
SQL Server Management Studio uses the SQL Server Client OLE DB provider, which requires the ODBC driver to be used inprocess. To enable this, from SSMS, navigate to Object Explorer > Server Objects > Linked Servers > Providers, right-click "SQLOLEDB", and select Properties > General > Provider options: > Allow inprocess. Confirm the change by clicking OK.Configure SQL Gateway
Configuring remote access to an ODBC data source in the SQL Gateway administration tool consists of the following steps:- Configure the proxying service on the Services tab.
- Configure database users on the Users tab.
- Configure TLS/SSL on the Other tab.
- Access services hosted behind a firewall by configuring SSH Tunnel.
Create a Linked Server from the UI
To create a linked server from the UI in SQL Server Management Studio:
- Open SQL Server Management Studio and connect to an instance of SQL Server.
- Expand the Server Objects node, right-click Linked Servers, and select New Linked Server. The New Linked Server dialog is displayed.
- In the General section, select Other data source and enter the following information:
- Linked server: Name the linked server.
- Provider: Select Microsoft OLE DB Driver for SQL Server or the latest Microsoft ODBC Driver for SQL Server.
- Data Source: Enter the hostname and port of the service, separated by a comma. If you are connecting through Tunneling, provide the mapped IP/Port of the tunnel. Note that a value of "localhost" refers to the machine where SQL Server is running, so be aware of that when your SQL Gateway service and your SQL Server instance are running on different machines.
- Catalog: Enter the system DSN as the catalog. For example, "CData MySQL Sys".
- In the Security section, select Be Made Using this Security Context and enter the username and password of a user you authorized on the Users tab in the SQL Gateway administration console.
Create a Linked Server Programmatically
In addition to using the SQL Server Management Studio UI to create a linked server, you can use stored procedures. The following inputs are required to create the linked server:- Server: The linked server name.
- Provider: Enter MSOLEDBSQL for the Microsoft OLE DB Driver for SQL Server or the latest Microsoft ODBC Driver for SQL Server.
- Datasrc: The host and port the service is running on, separated by a comma. Note that a value of "localhost" refers to the machine where SQL Server is running, so be aware of that when your SQL Gateway service and your SQL Server instance are running on different machines.
- Catalog: Enter the system DSN configured for the service. For example, "CData MySQL Sys".
- Srvproduct: Enter the product name of the data source. This can be an arbitrary value, such as "CData SQL Gateway" or an empty string.
To create the linked server and configure authentication to the SQL Gateway:
- Call sp_addlinkedserver to create the linked server:
EXEC sp_addlinkedserver @server='MySQL', @provider='MSOLEDBSQL', @datasrc='<Machine IP address>,1434', @catalog='CData MySQL Sys'; GO
- Allow SQL Server users to connect with the credentials of an authorized user of the service. Note that the credentials you use to connect to the service must map to a user you defined on the Users tab in the SQL Gateway administration tool.
EXEC sp_addlinkedsrvlogin @rmtsrvname='MySQL', @rmtuser='admin', @rmtpassword='test', @useself='FALSE', @locallogin=NULL; GO