PRB: SQL Application Role Errors with OLE DB Resource PoolingID: Q229564
|
When enabling Application Role for a SQL Server connection, you may get the following error:
The error occurs when sp_setapprole was called on a connection that was allocated from the resource pool. The same error occurs with the SQLOLEDB provider and SQL ODBC driver."sp_setapprole was not invoked correctly. Refer to the documentation for more information."
Turn off resource pooling, which ActiveX Data Objects (ADO) invokes by default. For example:
'For SQLOLEDB provider
'strConnect = "Provider=SQLOLEDB;server=SQL7Web;OLE DB Services = -2;uid=AppUser;pwd=AppUser;initial catalog=northwind"
' For MSDASQL provider
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; OLE DB Services= -2"
The following code reproduces the error:
Private Sub Command2_Click()
Dim adoCn1 As ADODB.Connection
Dim adoCn2 As ADODB.Connection
Set adoCn1 = GetConnection
Set adoCn2 = GetConnection
Set adoCn2 = Nothing
Set adoCn2 = GetConnection
Set adoCn2 = Nothing
Set adoCn2 = GetConnection 'Gives errors for both SQLOLEDB and ODBC
Set adoCn2 = Nothing
End Sub
Private Function GetConnection() As ADODB.Connection
Dim cn As ADODB.Connection
Dim sSQL As String
Dim strConnect As String
Set cn = New ADODB.Connection
'For OLEDB provider
strConnect = "Provider=SQLOLEDB;server=myServer;uid=AppUser;pwd=AppUser;initial catalog=northwind"
'Turn off Pooling ( all other services are enabled )
'strConnect = "Provider=SQLOLEDB;server=myServer;OLE DB Services= -2;uid=AppUser;pwd=AppUser;initial catalog=northwind"
'For ODBC driver
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; "
'Turn off Pooling
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; OLE DB Services= -2"
cn.ConnectionString = strConnect
cn.Open
sSQL = "sp_setapprole 'order_entry', 'password'"
cn.Execute sSQL
Set GetConnection = cn
End Function
Additional query words:
Keywords : kbMDAC kbOLEDB210 kbSQLServ kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2 kbMDAC210SP2
Version : WINDOWS:2.0,2.1; winnt:7.0
Platform : WINDOWS winnt
Issue type : kbprb
Last Reviewed: June 24, 1999