Opening a Password-Protected Data Set

Goal

You want your application to open a password-protected data set.
This recipe applies to the local, SAS/SHARE, IOM, and Base SAS providers. Sample code for ADO is included.
SAS supports three types of data set passwords: READ, WRITE, and ALTER. SAS also supports a PW= data set option that assigns the same password for each level of protection. To access a data set that is protected with the PW= data set option, set each ADO or OLE DB property that provides the level of access that you need.
Note: For complete information about SAS data set passwords, see SAS Language Reference: Concepts.

ADO Implementation

The SAS providers implement three ADO Recordset object properties that correspond to each of the SAS password types.
Recordset Properties and Corresponding SAS Password Types
Recordset Property Name
SAS Data Set Password Types
"SAS Read Password"
READ=
"SAS Write Password"
WRITE=
"SAS Alter Password"
ALTER=
The following sample code uses the "SAS Read Password" property to open a read-protected data set.
' obConnection is an open Connection object.
Dim obRecordset As New ADODB.Recordset

obRecordset.ActiveConnection = obConnection 
obRecordset.Properties("SAS Read Password") = "gurt96" 

' The second parameter on the Open method must remain empty.
obRecordset.Open source, , adOpenStatic, adLockReadOnly, adCmdTableDirect

OLE DB Implementation

The SAS providers implement three OLE DB rowset properties that correspond to each of the SAS password types. The OLE DB properties are part of the DBPROP_SAS_ROWSET customized property set.
Rowset Properties and Corresponding SAS Password Types
Rowset Property Name
SAS Data Set Password Types
"DBPROP_SAS_READPASSWORD"
READ=
"DBPROP_SAS_WRITEPASSWORD"
WRITE=
"DBPROP_SAS_ALTERPASSWORD"
ALTER=