Connecting to Local Data

Goal

You want to open an ADO Connection object in order to access data that is stored in one of these locations:
  • your local machine
  • a SAS Workspace server that is running on your local machine
  • a SAS/SHARE server that is running on your local machine
This recipe applies to the local, SAS/SHARE, and IOM providers. Sample code is included. This recipe applies only to ADO.
Note: Sample code for the Base SAS provider can be found in Connecting to Local Data (Single-User Server). There is no recipe for making a local connection by using the OLAP provider. Although it is technically possible to make a local connection to a SAS OLAP Server, a local configuration is unlikely.

Implementation

A local connection is the simplest connection that you can make. The following table explains the required scenario and contains sample code.
Sample Code for Local Connections
Provider
Connection Scenario and Sample Code
local provider
The data is on your local machine. You specify the physical location.
Dim obConnection As New ADODB.Connection

obConnection.Provider = "sas.LocalProvider"
obConnection.Properties("Data Source") = "c:\MySasData"
obConnection.Open
IOM provider
The SAS Workspace Server is running on your local machine.
Dim obConnection As New ADODB.Connection 
Dim connectionString As String

connectionString = "Provider=SAS.IOMProvider.9.2;Data Source=_LOCAL_"
obConnection.Open connectionString     
After the Connection object is opened, it is assigned to the specified server for the duration of the session.
SAS/SHARE provider
The SAS/SHARE server is running on your local machine. You specify the server's ID as the value of the "Data Source" property.
Dim obConnection As New ADODB.Connection

obConnection.Provider = "sas.SHAREProvider" 
obConnection.Properties("Data Source") = "shr1" 
obConnection.Open 
After the Connection object is opened, it is assigned to the specified server for the duration of the session.
For an explanation of the properties used in the sample code, see ADO Connection Properties for the SAS Providers.