SAS IT技术使用ADO Connection Object

摘自SAS网站

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.


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
always uses the latest version of the provider that is installed on a machine"SAS.provider"
"sas.LocalProvider"
"sas.ShareProvider"
"sas.IOMProvider"
"sas.OLAPProvider"
only uses a specific version of a provider"sas.provider.major version.minor version""sas.LocalProvider.9.0"

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

The SAS IOM Data Provider supports the following properties on the ADO Connection object:

PropertyValueRequired?
Data SourceUse 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. Yes
User IDUser ID that is used to authenticate against the server.No
PasswordPassword to use with the user ID in authenticating against the server.No
SAS Workspace IDA unique ID generated by the SAS Workspace Manager.No
SAS Logical NameAn entry name in your LDAP (Lightweight Directory Access Protocol) repository that defines an IOM server.No
SAS PortPort number of remote server.No
SAS Service NameA logical reference to the port associated with a remote server.No
SAS Machine DNS NameNetwork DNS name of the remote server.No
SAS ProtocolIOM protocol to use when connecting to the remote server.No
SAS Server TypeTabular data server or OLAP server. 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.


SAS OLAP Provider Connection Properties

The SAS OLAP Data Provider supports the following properties on the ADO Connection object:

PropertyValueRequired?
Data SourceThe name of the OLAP server to which you are connecting. Yes
User IDUser ID that is used to authenticate against the server.No
PasswordPassword to use with the user ID in authenticating against the server.No
SAS PortPort number of remote server.No
SAS Service NameA logical reference to the port associated with a remote server.No
SAS ProtocolIOM protocol to use when connecting to the remote server.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:

PropertyValueRequired?
Data SourceA physical directory that contains the SAS data set that you want to access with the connection.Yes
ModeadModeRead or adModeReadWriteNo
SAS File FormatThe SAS file format access method to associate with the connection.

Valid values: "V6", "V7", "V8", and "V9".

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:

PropertyValueRequired?
Data SourceThe server ID (established by the server administrator when the SAS/SHARE server is started).Yes
ModeadModeRead or adModeReadWriteNo
LocationThe node that the server is running on. Only if the node is not the one running the ADO application.
User IDThe user ID that is used to access a remote server.No
PasswordThe password that is used to access a remote server.No
SAS Server Access PasswordThe server access password (if one was established by the server administrator when the SAS/SHARE server was started).No
SAS Server ReleaseThe server access method to associate with the connection.

Valid values: "7", "8", and "9"

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.

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值