
ATL comp. for database access
Here's VB sample code for what I want to do (but in a thread neutral ATL
component):
Implements COMSVCSLib.ObjectControl
Public Function GetReadonlyRS(ByVal strConnect As String, _
ByVal strSQL As String _
) As ADODB.Recordset
Dim cnConn As ADODB.Connection
Dim rsResult As ADODB.Recordset
'create and open a db connection
Set cnConn = New ADODB.Connection
With cnConn
.ConnectionString = strConnect
.CursorLocation = adUseClient
.Open
End With
'create a new rs, set cursor type, lock type, cursor location etc
Set rsResult = New ADODB.Recordset
With rsResult
.LockType = adLockReadOnly
.CursorType = adOpenStatic
.CursorLocation = cnConn.CursorLocation
Set .ActiveConnection = cnConn
End With
'execute the query
rsResult.Open strSQL
'disconnect the rs
Set rsResult.ActiveConnection = Nothing
'set the result to the result rs
Set GetReadonlyRS = rsResult
'release and cleanup the local result rs and the connection
Set rsResult = Nothing
cnConn.Close
Set cnConn = Nothing
'tell COM+ we're done
GetObjectContext.SetComplete
End Function
Private Sub ObjectControl_Activate()
'nothing
End Sub
Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = True
End Function
Private Sub ObjectControl_Deactivate()
'nothing
End Sub