I am experimenting a bit with COM+.. Is this basic example of mine
a "proper" implementation ? Feel free to critisize:
VB Code:
  1. Implements ObjectControl
  2.  
  3. Private objContext As ObjectContext
  4. Private Const strAppName = "ComTest"
  5.  
  6. Option Explicit
  7.  
  8. Private Sub ObjectControl_Activate()
  9.     Set objContext = GetObjectContext()
  10. End Sub
  11. Private Function ObjectControl_CanBePooled() As Boolean
  12.     ObjectControl_CanBePooled = False
  13. End Function
  14. Private Sub ObjectControl_Deactivate()
  15.     Set objContext = Nothing
  16. End Sub
  17.  
  18. 'Get absolutePath of System
  19. Public Function getAbsolutePath() As String
  20.   Dim strPathTranslated, strApplicationPath As String
  21.   Dim objRequest As Request
  22.  
  23.   Set objRequest = objContext("Request")
  24.  
  25.   strPathTranslated = objRequest.ServerVariables("PATH_TRANSLATED")
  26.   strApplicationPath = Left(strPathTranslated, InStrRev
  27. (strPathTranslated, strAppName, -1, 1) + Len(strAppName))
  28.   getAbsolutePath = strApplicationPath
  29.  
  30.   Set objRequest = Nothing
  31. End Function
  32.  
  33. 'Create as Database Connection
  34. Public Function ConnectToDB(ByVal ConnectionString As String) As
  35. ADODB.Connection
  36.   Set ConnectToDB = CreateObject("ADODB.Connection")
  37.   ConnectToDB.Open ConnectionString
  38. End Function
  39.  
  40. 'Create a recordset
  41. Function CreateRS(ByVal source As String, ByRef objConn As Variant, ByVal
  42. cursortype As Integer, ByVal locktype As Integer, ByVal options As
  43. Integer) As ADODB.Recordset
  44.   Set CreateRS = CreateObject("ADODB.Recordset")
  45.   CreateRS.Open source, objConn, cursortype, locktype, options
  46. End Function
  47.  
  48. Function strBaseString() As String
  49.   Dim strBaseConn As String
  50.   strBaseConn = "PROVIDER=MSDASQL;" & _
  51.                 "DRIVER={Microsoft Access Driver (*.mdb)};" & _
  52.                 "UID=admin;PWD=opensesame;" & _
  53.                 "DBQ=" & getAbsolutePath() & "Data.mdb"
  54.   strBaseString = strBaseConn
  55. End Function
Usage:
VB Code:
  1. <%
  2. Dim objTest, objConn, objRS
  3. Set objTest = Server.CreateObject("COM.Connection")
  4. Response.Write objTest.strBaseString() & "<br>"
  5. Response.Write objTest.getAbsolutePath() & "<br>"
  6. Set objConn = objTest.ConnectToDB(objTest.strBaseString())
  7. Set objRS = objTest.CreateRS("SELECT * FROM Books;",objConn,0 ,1 ,1)
  8. Do While Not objRS.EOF
  9.   Response.Write objRS("Title") & " " & objRS("ISBN") & "<BR>"
  10.   objRS.MoveNext
  11. Loop
  12. objRS.Close
  13. Set objRS = Nothing
  14. objConn.Close
  15. Set objConn = Nothing
  16. Set objTest = Nothing
  17. %>