You are on page 1of 3

Opening an ADO Connection Object

http://support.sas.com/documentation/tools/oledb/dbs001.htm

Providing software solutions since 1976

Opening an ADO Connection Object


In this recipe, you learn several ways to open an ADO Connection object. You will also find lists of the required and optional connection properties for each of the SAS Data Providers. Applies to: All SAS Data Providers Implement using: ADO

Overview
To open a Connection object, you must specify which provider to use and the appropriate connection properties. After you have this information, you can use one of these methods to send the information to your selected SAS Data Provider. Method 1: Use a Connection String Method 2: Use the Connection Object's ConnectionString Property Method 3: Use the Connection Object's Provider Property

Identifying the Provider


To specify the provider in your application, you enter its ProgID, which is a unique name that identifies a COM component. All providers support both version-dependent and version-independent ProgIDs, which enables you to install different versions of the providers on the same system and to write applications that use specific versions. To create an application that... Use this form... Examples "sas.LocalProvider" "sas.ShareProvider" "sas.IOMProvider" "sas.OLAPProvider" "sas.LocalProvider.9.0"

always uses the latest version of the provider that is installed on a machine

"SAS.provider"

only uses a specific version of a provider

"sas.provider.major version.minor version"

To maintain compatibility with previous releases, the special ProgID "sas.provider.1" is maintained as a synonym for the version-independent ProgID. For example, the last SAS IOM Data Provider that was installed on the system can be identified in either of these two ways: "sas.IOMProvider" "sas.IOMProvider.1" The SAS 9.1 IOM Data Provider can be specifically identified as "sas.IOMProvider.9.1".

Connection Properties
Each provider supports its own unique set of Connection object properties. To review the syntax used by each provider, see the following sections: SAS IOM Provider Connection Properties SAS OLAP Provider Connection Properties SAS Local Provider Connection Properties SAS/SHARE Provider Connection Properties

SAS IOM Provider Connection Properties The SAS IOM Data Provider supports the following properties on the ADO Connection object: Property Value Use the keyword "_LOCAL_" to indicate a local instance of the IOM server. To specify a remote server, enter a user-defined name that will be used to refer to the data source. User ID that is used to authenticate against the server. Password to use with the user ID in authenticating against the server. A unique ID generated by the SAS Workspace Manager. An entry name in your LDAP (Lightweight Directory Access Protocol) repository that defines an IOM server. Port number of remote server. A logical reference to the port associated with a remote server. Network DNS name of the remote server. IOM protocol to use when connecting to the remote server. Tabular data server or OLAP server. Required?

Data Source

Yes

User ID Password SAS Workspace ID SAS Logical Name SAS Port SAS Service Name SAS Machine DNS Name SAS Protocol SAS Server Type

No No No No No No No No No

The simplest connection that you can make with the IOM provider is to a server that is running on your local Windows machine. Such a server is bound exclusively to the Connection object that instantiated it. For this type of connection, you only need to specify a "Data Source" property value of "_LOCAL_" , as shown in the following code:

obConnection.Provider = "sas.IOMProvider" obConnection.Properties("Data Source") = "_LOCAL_" obConnection.Open

See also: Connecting to a IOM Remote Server Connecting to a Remote SAS OLAP Server with the IOM Provider Reusing an Existing IOM Workspace.

1 de 3

26/12/2011 18:05

Opening an ADO Connection Object

http://support.sas.com/documentation/tools/oledb/dbs001.htm

SAS OLAP Provider Connection Properties The SAS OLAP Data Provider supports the following properties on the ADO Connection object: Property Data Source User ID Password SAS Port SAS Service Name SAS Protocol Value The name of the OLAP server to which you are connecting. User ID that is used to authenticate against the server. Password to use with the user ID in authenticating against the server. Port number of remote server. A logical reference to the port associated with a remote server. IOM protocol to use when connecting to the remote server. Required? Yes No No No No No

See also: Connecting to a Remote SAS OLAP Server

Local Provider Connection Properties The local provider supports the following properties on the ADO Connection object: Property Data Source Value A physical directory that contains the SAS data set that you want to access with the connection. adModeRead or adModeReadWrite The SAS file format access method to associate with the connection. Valid values: "V6", "V7", "V8", and "V9". Required? Yes

Mode

No

SAS File Format

No

The local provider is usually the simplest to configure with an ADO connection. You only need to specify the physical location of the SAS files that you want to access. For example, if your data sets can be found in c:\my documents\sas files, then the following Visual Basic code will open the connection that you need:

obConnection.Provider = "sas.LocalProvider" obConnection.Properties("Data Source") = "c:\my documents\sas files" obConnection.Open

See also: Specifying a File Format

SAS/SHARE Provider Connection Properties The SAS/SHARE provider supports the following properties on the ADO Connection object: Property Data Source Mode Location User ID Password SAS Server Access Password SAS Server Release adModeRead or adModeReadWrite The node that the server is running on. The user ID that is used to access a remote server. The password that is used to access a remote server. The server access password (if one was established by the server administrator when the SAS/SHARE server was started). The server access method to associate with the connection. Valid values: "7", "8", and "9" No Value The server ID (established by the server administrator when the SAS/SHARE server is started). Required? Yes No Only if the node is not the one running the ADO application. No No No

The simplest connection that you can make using the SAS/SHARE provider is to a SAS/SHARE server that is running on your local Windows machine. After the Connection object is opened, it is assigned to this server for the duration of the session. For this type of a connection, you only need to specify the server's ID as the "Data Source."

obConnection.Provider = "sas.SHAREProvider" obConnection.Properties("Data Source") = server_id obConnection.Open

See also: Connecting to a Remote SAS/SHARE Server Starting a Single-User Local Server with the SAS/SHARE Provider Connecting to a Specific SAS/SHARE Server Version

Three Ways to Open the Connection Object


Here is a quick overview of three ways to open an ADO Connection object: Method 1: Use a Connection String Set the Connection object's properties in a one-line string. The following sample code shows the format.
obConnection.Open "Provider=provider_name;Data Source=data_source;other_provider_specific_info"

Method 2: Use the Connection Object's ConnectionString Property Set the Connection object's ConnectionString property, and call the Open method without specifying any parameters. The following sample code illustrates how this is done.

2 de 3

26/12/2011 18:05

Opening an ADO Connection Object

http://support.sas.com/documentation/tools/oledb/dbs001.htm

obConnection.ConnectionString = "Provider=provider_name;Data Source=data_source;other_provider_specific_info" obConnection.Open

Method 3: Use the Connection Object's Provider Property Set the Connection object's Provider property, and then set individual property values by using the Connection object's Properties collection. The following sample code illustrates how this is done.
obConnection.Provider = "provider_name" obConnection.Properties("Data Source") = "data_source" ' Set additional properties via the Properties collection as needed obConnection.Open

Contact Us | Sitemap | RSS Feeds | www.sas.com | Terms of Use & Legal Information | Privacy Statement Copyright 2011 SAS Institute Inc. All Rights Reserved.

3 de 3

26/12/2011 18:05

You might also like