--- title: "Using Linked Servers in SMO | Microsoft Docs" ms.custom: "" ms.date: "08/06/2017" ms.prod: sql ms.prod_service: "database-engine" ms.reviewer: "" ms.technology: ms.topic: "reference" helpviewer_keywords: - "linked servers [SQL Server], SMO" ms.assetid: 0ea8837b-2596-4df1-b065-3bb717c9f22c author: "markingmyname" ms.author: "maghan" monikerRange: "=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # Using Linked Servers in SMO [!INCLUDE[appliesto-ss-asdb-asdw-xxx-md](../../../includes/appliesto-ss-asdb-asdw-xxx-md.md)] A linked server represents an OLE DB data source on a remote server. Remote OLE DB data sources are linked to the instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] by using the object. Remote database servers can be linked to the current instance of [!INCLUDE[msCoName](../../../includes/msconame-md.md)] [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] by using an OLE DB Provider. In SMO, linked servers are represented by the object. The property references a collection of objects. These store the logon credentials that are required to establish a connection with the linked server. ## OLE-DB Providers In SMO, installed OLE-DB providers are represented by a collection of objects. ## Example For the following code examples, you will have to select the programming environment, programming template and the programming language to create your application. For more information, see [Create a Visual C# SMO Project in Visual Studio .NET](../../../relational-databases/server-management-objects-smo/how-to-create-a-visual-csharp-smo-project-in-visual-studio-net.md). ## Creating a link to an OLE-DB Provider Server in Visual C# The code example shows how to create a link to a [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] OLE DB, heterogeneous data source by using the object. By specifying [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] as the product name, data is accessed on the linked server by using the [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Client OLE DB Provider, which is the official OLE DB provider for [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)]. ```csharp //Connect to the local, default instance of SQL Server. { Server srv = new Server(); //Create a linked server. LinkedServer lsrv = default(LinkedServer); lsrv = new LinkedServer(srv, "OLEDBSRV"); //When the product name is SQL Server the remaining properties are //not required to be set. lsrv.ProductName = "SQL Server"; lsrv.Create(); } ``` ## Creating a link to an OLE-DB Provider Server in PowerShell The code example shows how to create a link to a [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] OLE DB, heterogeneous data source by using the object. By specifying [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] as the product name, data is accessed on the linked server by using the [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] Client OLE DB Provider, which is the official OLE DB provider for [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)]. ```powershell #Get a server object which corresponds to the default instance $svr = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server #Create a linked server object which corresponds to an OLEDB type of SQL server product $lsvr = New-Object -TypeName Microsoft.SqlServer.Management.SMO.LinkedServer -argumentlist $svr,"OLEDBSRV" #When the product name is SQL Server the remaining properties are not required to be set. $lsvr.ProductName = "SQL Server" #Create the Database Object $lsvr.Create() ```