p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_databases thread: wrox beginning vb6 database programming page 699/about Visitors.Dll


Message #1 by "Pappas Nikolaos" <pappas@c...> on Mon, 4 Dec 2000 20:02:09 +0200
In case the user's dir path is not Known or other problems maybe.

to make this dll work use the code as it is corrected for me thanks to Imar

Spaanjaars.

Imar thanks for the help.

There's the code I think could be usefull some ways so forgive the sise of

this message.

============================================================================

======================

Option Explicit





Public Function setVisitor(ByVal firstName As Variant, ByVal lastName As

Variant, ByVal Email As Variant) As Variant



Dim adoConnection As ADODB.Connection

Dim adoRecordset As ADODB.Recordset

Dim connectString As String

         Dim objLocalContext As ObjectContext

         Dim objServer As ASPTypeLibrary.Server

         Set objLocalContext = GetObjectContext()

         Set objServer = objLocalContext("Server")



connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

                 "Data Source =" & objServer.MapPath("/Visitors.mdb") &

";Persist Security Info=False"



Set adoConnection = CreateObject("ADODB.Connection")

Set adoRecordset = CreateObject("ADODB.Recordset")



adoConnection.Open connectString

adoRecordset.Open "SELECT * FROM SiteVisitors", adoConnection, _

                               adOpenDynamic, adLockOptimistic



With adoRecordset

   .AddNew

   !firstName = firstName

   !lastName = lastName

   !Email = Email

   !previousVisit = Now()

   !totalVisits = 1

   .Update

End With



'-- Return a unique ID so we can set the cookie

setVisitor = adoRecordset!cookieID



'-- Close the recordset and the connection

adoRecordset.Close

adoConnection.Close



End Function



Public Function getVisitor(ByVal visitorNumber As Variant) As Variant



Dim adoConnection As ADODB.Connection

Dim adoRecordset As ADODB.Recordset

Dim connectString As String

Dim sqlString As String

Dim visitorArray() As Variant   'must be a variant



         Dim objLocalContext As ObjectContext

         Dim objServer As ASPTypeLibrary.Server

         Set objLocalContext = GetObjectContext()

         Set objServer = objLocalContext("Server")



connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

                 "Data Source =" & objServer.MapPath("/Visitors.mdb") &

";Persist Security Info=False"





Set adoConnection = CreateObject("ADODB.Connection")

Set adoRecordset = CreateObject("ADODB.Recordset")



adoConnection.Open connectString



sqlString = "Select * From SiteVisitors WHERE CookieID = " & visitorNumber



adoRecordset.Open sqlString, adoConnection, adOpenDynamic, adLockOptimistic



If (adoRecordset.BOF) And (adoRecordset.EOF) Then

  ReDim visitorArray(1)

  visitorArray(0) = "Not Found"

  visitorArray(1) = "Not Found"

  visitorArray(2) = "Not Found"

  visitorArray(3) = "Not Found"

Else

  ReDim visitorArray(4)

  visitorArray(0) = adoRecordset!firstName

  visitorArray(1) = adoRecordset!lastName

  visitorArray(2) = adoRecordset!previousVisit

  adoRecordset!previousVisit = Now()

  adoRecordset!totalVisits = adoRecordset!totalVisits + 1

  adoRecordset.Update

  visitorArray(3) = adoRecordset!totalVisits

End If



adoRecordset.Close

adoConnection.Close



getVisitor = visitorArray

End Function

============================================================================

=======

---------------------

Imar's answer

---------------------

Check! I think I know what the problem is.

Server.MapPath is a method of one of the intrinsic objects of ASP.

You'll need a reference to them in your DLL.



Do the following:



1. Set a reference to COM+ Services type library (on WIndows 2000) or to

Microsoft Transaction Type Library on Windows NT 4, I don't know the exact

name for it on Windows NT 4, but it is something like that. The DLL is

called mtxas.dll, so you can search for it)



2. Get a reference to the Server Object like this:

         Dim objLocalContext As ObjectContext

         Dim objServer As ASPTypeLibrary.Server

         Set objLocalContext = GetObjectContext()

         Set objServer = objLocalContext("Server")



Now the object objServer is sort of like your real Server object. So this

will work:



objServer.Mappath("/database")



A second way of doing this, is to use Server.Mappath in your ASP page, and

then pass the value of it to your DLL.



HtH



Imar

------------------------------------------------------------

 References to make the dll work:

------------------------------------------------------------

Visual Basic For Applications                   MSVBVM60.DLL

Visual Basic runtime objects and procedures     MSVBVM60.DLL\3

Visual Basic objects and procedures             \Microsoft Visual

Studio\VB98\VB6.OLB

OLE Automation                                  STDOLE2.TLB

Microsoft ActiveX Data Objects 2.5 Library      PROGRAM FILES\COMMON

FILES\SYSTEM\ADO\msado15.c

Microsoft Transaction Server Type Library       MTXAS.DLL

Microsoft Active Server Pages Object Library    ASP.DLL

-------------------------------------------




  Return to Index