You can use application roles in a Visual Basic (VB) Data Environment. To avoid resource-pooling problems, include the OLE DB Services = -2 option in the Connection object's ConnectionSource property. When you define the connection in the Data Environment UI, the dialog box has nowhere to enter the OLE DB Services option. However, you can add the extra text manually in the ConnectionSource property's connection string. The following example shows a completed ConnectionSource that uses Windows 2000/Windows NT authentication against a local server:

Provider=SQLOLEDB.1;Integrated Security=SSPI;OLE DB Services = -2;Persist
Security Info=False;Initial Catalog=Products;Data Source=(local

You can execute the sp_setapprole stored procedure in a Data Environment Connection object's ConnectionComplete event. This stored procedure activates the application role as soon as the connection is open, and the application role remains active as long as the connection endures. Figure A shows an example of how to use a Data Environment connection's ConnectComplete event procedure to execute the sp_setapprole stored procedure and activate the application role. After the stored procedure activates the application role, any Command and Recordset objects that the Connection object creates execute within the application role's security context.