This documentation is archived and is not being maintained.

How to: Link to an OLE-DB Provider Server in Visual Basic .NET

This section describes how to create a linked server to enable distributed queries on a heterogeneous OLE DB data source by using Visual Basic .NET.

The code example shows how to create a link to a SQL Server OLE DB data source by using the LinkedServer object. By specifying SQL Server as the product name, data is accessed on the linked server by using the Microsoft SQL Server Native Client OLE DB Provider, which is the official OLE DB provider for SQL Server.

  1. Start Visual Studio 2005.

  2. From the File menu, select New Project. The New Project dialog box appears.

  3. In the Project Types pane, select Visual Basic. In the Templates pane, select Console Application.

  4. (Optional) In the Name box, type the name of the new application.

  5. Click OK to load the Visual Basic console application template.

  6. On the Project menu, select Add Reference item. The Add Reference dialog box appears. Select Browse, locate the SMO assemblies in the C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies folder, and select the following files:





  7. On the View menu, click Code.-Or-Select the Module1.vb window to display the code window.

  8. In the code, before any declarations, type the following Imports statements to qualify the types in the SMO namespace:

    Imports Microsoft.SqlServer.Management.Smo
    Imports Microsoft.SqlServer.Management.Common
  9. Insert the code that follows this procedure into the main program.

  10. Run and build the application.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Create a linked server.
Dim lsrv As 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"