By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,742 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,742 IT Pros & Developers. It's quick & easy.

ADODB.Connection error '800a0e78'

P: 5
Hi I am new to ASP and I am getting this error:

ADODB.Connection error '800a0e78'

Operation is not allowed when the object is closed.

/members/asp/util.asp, line 67


the code line in the util.asp looks like this:

Sub CreateVisitorID(dcnDB)

Dim rsData
Dim strSQL

If Request.Cookies("VisitorID") <> "" Then Exit Sub

strSQL = "INSERT INTO Visitors " & "(VisitDate, Host) " & "VALUES (" & "#" & Date & " " & Time & "#, " & "'"

If Request.ServerVariables("REMOTE_HOST") <> "" Then
strSQL = strSQL & Request.ServerVariables("REMOTE_HOST")
Else
strSQL = strSQL & Request.ServerVariables("REMOTE_ADDR")
End IF

strSQL = strSQL & "')"

Application.Lock
dcnDB.Execute strSQL (this is line 67)
strSQL = "SELECT Max(VisitorID) FROM Visitors"
Set rsData = dcnDB.Execute(strSQL)
Response.Cookies("VisitorID") = rsData(0)
Application.Unlock

rsData.Close

End Sub


Can any please help
Feb 7 '08 #1
Share this Question
Share on Google+
7 Replies


CroCrew
Expert 100+
P: 563
Can you post your connection string (without username and password). Also please let us know the type of database that you are using.

CroCrew~
Feb 7 '08 #2

P: 5
it links to a .mdb file

this is the full code for the file

<%
Option Explicit
%>
<!-- #include file=adovbs.inc -->
<%
Const ACTION_VALIDATE = "v"
Const MODE_ADD = "a"
Const MODE_MODIFY = "m"
Const MODE_POST = "p"
Const MODE_REPLY = "r"

Function OpenDB()
Dim dcnDB
Dim strDatabaseLocation ' As String
Dim rsForMem ' As ADODB.Recordset
Dim strSQL ' As String
On Error Resume Next

strDatabaseLocation = Server.MapPath("../../../data/file.mdb")

Set dcnDB = Server.CreateObject("ADODB.Connection")

dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;Data Source=" & strDatabaseLocation

dcnDB.Open

Set OpenDB = dcnDB

End Function

Sub CloseDB(dcnDB)

dcnDB.Close

End Sub



Sub CheckForLogin()

If Request.Cookies("MemberID") = "" Then
Response.Redirect "../pages/hpage.html"

End If

End Sub
%>
<%
Sub CreateVisitorID(dcnDB)

Dim rsData
Dim strSQL

If Request.Cookies("VisitorID") <> "" Then Exit Sub

strSQL = "INSERT INTO Visitors " & "(VisitDate, Host) " & "VALUES (" & "#" & Date & " " & Time & "#, " & "'"

If Request.ServerVariables("REMOTE_HOST") <> "" Then
strSQL = strSQL & Request.ServerVariables("REMOTE_HOST")
Else
strSQL = strSQL & Request.ServerVariables("REMOTE_ADDR")
End IF

strSQL = strSQL & "')"

Application.Lock
dcnDB.Execute strSQL
strSQL = "SELECT Max(VisitorID) FROM Visitors"
Set rsData = dcnDB.Execute(strSQL)
Response.Cookies("VisitorID") = rsData(0)
Application.Unlock

rsData.Close

End Sub

Sub RecordSearchInfo(dcnDB, strSearch, strSearch1, strSearch2, strSearch3, searchMemID, lngResultCount)
On Error Resume Next
Dim strSQL

CreateVisitorID dcnDB

strSQL = "INSERT INTO VisitorSearches " & "(VisitorID, SearchTerms, SearchTerms1, SearchTerms2, SearchTerms3, MemID, SearchResults) VALUES (" & Request.Cookies("VisitorID") & ", '" & Replace(strSearch, "'", "''") & "' , '" & Replace(strSearch1, "'", "''") & "', '" & Replace(strSearch2, "'", "''") & "', '" & Replace(strSearch3, "'", "''") & "', '" & Replace(searchMemID, "'", "''")& "', " & lngResultCount & ")"
dcnDB.Execute strSQL

End Sub
%>

<%
Sub MapRequestInfo (dcnDB, MapType, County)

Dim strSQL

CreateVisitorID dcnDB

strSQL = "INSERT INTO MapRequests " & "(VisitorID, MapType, County) VALUES (" & Request.Cookies("VisitorID") & ", '" & Replace (MapType, "'", "''") & "' , '" & Replace(County, "'", "''") & "'" & ")"

dcnDB.Execute strSQL

End Sub

%>
Feb 7 '08 #3

DrBunchman
Expert 100+
P: 979
Hi Simon,

When you call the sub CreateVisitorID(dcnDB) are you passing in an open database connection? Somewhere prior to calling this sub you must first call the function OpenDB() and assign it to your database connection object. e.g

Expand|Select|Wrap|Line Numbers
  1.  Dim dcnDB 
  2. dcnDB = OpenDB()
  3. CreateVisitorID(dcnDB)
  4.  
Hope this helps,

Dr B
Feb 8 '08 #4

markrawlingson
Expert 100+
P: 346
I would agree with DrBunchman, that is probably where the problem lies.

However I'd also like to point out that you may want to try changing the sub routine to a function if you're going to be passing it your connection object, or just remove that argument all together and setup your connection object in such a way that it doesn't need to be called or passed through as an argument.

I've never been able to successfully pass an object as an argument to a Subroutine, but I've been very successful doing this with functions.

I had a similar problem a few months back and resolved the issue by simply changing the sub to a function. That particular scenario has lead me to believe that subroutines cannot accept an object as an argument, but I could be wrong about that.

Hope that helps,

Sincerely,
Mark
Feb 9 '08 #5

P: 5
this is the results.asp page

<!-- #include file="util.asp" -->
<%
Dim dcnDB ' As ADODB.Connection
Dim rsData ' As ADODB.Recordset
Dim strSQL ' As String
Dim blnaddedWhere
Dim blnAddedAnd
Dim strAddress
Dim objFSO
Dim strFile
Dim strImage
Const RECORDSPERPAGE = 2
Dim intPages
Dim intPageNum
Dim intCount
Dim Count
Dim endrow
Dim i
Dim z
Dim arrPages(10)
Dim strDataTable
Dim arrAll()
Dim v
Dim y
Dim x
Dim intMemID
Dim arrSQL()
Dim intCountRecords
Dim intArrCount
Dim strSQL1

SET dcnDB = OpenDB()
SET rsData = Server.CreateObject ("ADODB.Recordset")

If Request("strSQL") = "" Then

If Request("search_type") = "coName" Then
If Request("searchName") <> "" Then
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND MemName LIKE '%" & Request("searchName") & "%'" & " ORDER By (MemName)"
Else
strSQL = "SELECT * FROM tblMembers WHERE Active=True" & " ORDER By (MemName)"
End if
Elseif Request("search_type") = "coLocationEngland" Then

If Request("area") = "England (all)" Then
strSQL = "SELECT * FROM tblMembers Where Active=True AND Country = 'ENGLAND'"
Else
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Location ='" & Request("area") & "'" & " ORDER By (MemName)"
End if

Elseif Request("search_type") = "coLocationScotland" Then

If Request("area") = "Scotland (all)" Then
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Country = 'SCOTLAND'"
Else
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Location ='" & Request("area") & "'" & " ORDER By (MemName)"
End if

Elseif Request("search_type") = "coLocationWales" Then

If Request("area") = "Wales (all)" Then
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Country = 'WALES'"
Else
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Location ='" & Request("area") & "'" & " ORDER By (MemName)"
End if

Elseif Request("search_type") = "coLocationNI" Then

strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Country = 'N IRELAND'"

Elseif Request("search_type") = "worldWide" Then

If Request("area") = "Worldwide (please select)" Then
strSQL = "SELECT * FROM tblMembers WHERE Active=True"
Else
strSQL = "SELECT * FROM tblMembers WHERE Active=True AND Location ='" & Request("area") & "'" & " ORDER By (MemName)"
End if

Elseif Request("search_type") = "criteriaLocation" Then

strSQL = "SELECT * FROM qryMemAreas" & " WHERE Active=True"

blnAddedAnd = False

If Request("acMain") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & " acMain=True"
End if
If Request("idCard") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "idCard=True"
End if
If Request("acManu") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "acManu=True"
End if
If Request("secInHouse") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "secInHouse=True"
End if
If Request("secAirport") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "secAirport=True"
End if
If Request("secIT") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "secIT=True"
End if
If Request("arc") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "arc=True"
End if
If Request("insurance") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "insurance=True"
End if
If Request("baliffs") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "baliffs=True"
End if
If Request("intruderMain") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "intruderMain=True"
End if
If Request("carpark") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "carpark=True"
End if
If Request("intruderManu") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "intruderManu=True"
End if
If Request("cashTransit") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "cashTransit=True"
End if
If Request("intruderMon") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "intruderMon=True"
End if
If Request("CCTVStaff") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "CCTVStaff=True"
End if
If Request("investigations") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "investigations=True"
End if
If Request("CCTVMain") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "CCTVMain=True"
End if
If Request("keyHolding") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "keyHolding=True"
End if
If Request("CCTVManu") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "CCTVManu=True"
End if
If Request("locksmiths") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "locksmiths=True"
End if
If Request("CCTVRemote") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "CCTVRemote=True"
End if
If Request("mannedGuard") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "mannedGuard=True"
End if
If Request("closeProtection") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "closeProtection=True"
End if
If Request("maritimeSec") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "maritimeSec=True"
End if
If Request("Comms") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "Comms=True"
End if
If Request("mobPatrols") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "mobPatrols=True"
End if
If Request("reception") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "reception=True"
End if
If Request("perimeterSEInstall") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "perimeterSEInstall=True"
End if
If Request("perimeterSEManu") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "perimeterSEManu=True"
End if
If Request("wasteDesc") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "wasteDesc=True"
End if
If Request("publisher") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "publisher=True"
End if
If Request("consultantSec") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "consultantSec=True"
End if
If Request("recruitment") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "recruitment=True"
End if
If Request("courtSec") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "courtSec=True"
End if
If Request("retailSec") = "Y" Then


If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "retailSec=True"
End if
If Request("crimePre") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "crimePre=True"
End if
If Request("storeDec") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "storeDec=True"
End if
If Request("dogs") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "dogs=True"
End if
If Request("screening") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "screening=True"
End if
If Request("doorSupers") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "doorSupers=True"
End if
If Request("secAss") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "secAss=True"
End if
If Request("escDel") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "escDel=True"
End if
If Request("secHardManu") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "secHardManu=True"
End if
If Request("exhibSec") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "exhibSec=True"
End if
If Request("surveillance") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "surveillance=True"
End if
If Request("facsMan") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "facsMan=True"
End if
If Request("training") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "training=True"
End if
If Request("fireInstall") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "fireInstall=True"
End if
If Request("uniforms") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "uniforms=True"
End if
If Request("fireManu") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "fireManu=True"
End if
If Request("vehicleSec") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "vehicleSec=True"
End if
If Request("fireMoni") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "fireMoni=True"
End if
If Request("voids") = "Y" Then
If Not blnAddedAnd Then
strSQL = strSQL & " AND "
blnAddedAnd = True
Else
strSQL = strSQL & " OR "
End if
strSQL = strSQL & "voids=True"
End if

If Request("SelectLocation") <> "Location (Please Select)" Then

If Request("location") = "England (all)" Then
strSQL = strSQL & " AND Country = 'England'"
Elseif Request("location") = "Scotland (all)" Then
strSQL = strSQL & " AND Country = 'Scotland'"
Elseif Request("location") = "Wales (all)" Then
strSQL = strSQL & " AND Country = 'Wales'"
Elseif Request("location") = "Northern Ireland (all)" Then
strSQL = strSQL & " AND Country = 'Northern Ireland' "
Elseif Request("location") = "Scotland (all)" Then
strSQL = strSQL & " AND Country = 'Scotland'"
Else
strSQL = strSQL & " AND Country = '" & Request("SelectLocation") & "'" & " AND Area ='" & Request("location") & "'"
End if

End if
strSQL = strSQL & " ORDER By (MemName)"
End if
Else
strSQL = Request("strSQL")
End if

' Response.Cookies("strSQL") = strSQL

rsData.Open strSQL, dcnDB, adOpenKeyset, adLockOptimistic

If rsData.BOF = True AND rsData.EOF = True Then
rsData.Close
CloseDB (dcnDB)
Response.Redirect "noResults.asp"
Else


'----- FILTER OUT DUPLICATE RECORDS ------

'-------- Get the number of records to ReDim the array
rsData.Close
rsData.Open strSQL , dcnDB, adOpenKeyset, adLockOptimistic
rsData.MoveLast
intCountRecords = rsData.RecordCount
rsData.Close

ReDim arrAll (intCountRecords)

rsData.Open strSQL , dcnDB, adOpenKeyset, adLockOptimistic

'--------- Fill the array with all records
y = 0

Do While Not rsData.EOF
arrAll(y) = rsData("MemID")
y = y + 1
rsData.MoveNext
Loop

'==== Already checked for null recordsets - must be at least one
'-- Load the First MemID
intMemID = CInt(arrAll(0))

'-- Assign the first array value to the new filtered array
ReDim arrSQL(1)
arrSQL(0) = intMemID

intArrCount = 0

x = 1

'-- First array value 0 already filled so v = 1 OK
For v = 1 to intCountRecords
'-- Test to see if next value is the same as last
If intMemID = arrAll(v) Then
intMemID = CInt(arrAll(v))
Else
'-- Assign subsequent array values
x = x+1
ReDim Preserve arrSQL(x)
arrSQL(x-1) = intMemID
intMemID = CInt(arrAll(v))
intArrCount = intArrCount + 1

End if
Next

x = 0

strSQL = "SELECT * FROM tblMembers WHERE MemID=" & arrSQL(0)

For x = 1 to intArrCount

strSQL = strSQL & " OR MemID=" & arrSQL(x)

Next

strSQL = strSQL & " ORDER By (MemName)"
rsData.Close
CloseDB (dcnDB)
Response.Redirect "search_results.asp?strSQL=" & strSQL
End if

%>
Feb 23 '08 #6

P: 5
this is the util.asp page

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Option Explicit
  3. %>
  4. <!-- #include file=adovbs.inc -->
  5. <%
  6. Const ACTION_VALIDATE = "v"
  7. Const MODE_ADD = "a"
  8. Const MODE_MODIFY = "m"
  9. Const MODE_POST = "p"
  10. Const MODE_REPLY = "r"
  11.  
  12. Function OpenDB()
  13. Dim dcnDB
  14. Dim strDatabaseLocation         ' As String
  15. Dim rsForMem                    ' As ADODB.Recordset
  16. Dim strSQL                    ' As String
  17. On Error Resume Next
  18.  
  19. strDatabaseLocation = Server.MapPath("../../data/file.mdb")
  20.  
  21. Set dcnDB = Server.CreateObject("ADODB.Connection")
  22.  
  23. dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;Data Source=" & strDatabaseLocation
  24.  
  25. dcnDB.Open
  26.  
  27. Set OpenDB = dcnDB
  28.  
  29. End Function
  30.  
  31. Sub CloseDB(dcnDB)
  32.  
  33. dcnDB.Close
  34.  
  35. End Sub
  36.  
  37.  
  38.  
  39. Sub CheckForLogin()
  40.  
  41.     If Request.Cookies("MemberID") = "" Then
  42.      Response.Redirect "../pages/hpage.html"
  43.  
  44.     End If
  45.  
  46. End Sub
  47. %>
  48. <%
  49. Sub CreateVisitorID(dcnDB)
  50.  
  51.     Dim rsData
  52.     Dim strSQL
  53.  
  54.         If Request.Cookies("VisitorID") <> "" Then Exit Sub
  55.  
  56.         strSQL = "INSERT INTO Visitors " & "(VisitDate, Host) " & "VALUES (" & "#" & Date & " " & Time & "#, " & "'"
  57.  
  58.         If Request.ServerVariables("REMOTE_HOST") <> "" Then
  59.         strSQL = strSQL & Request.ServerVariables("REMOTE_HOST")
  60.         Else
  61.         strSQL = strSQL & Request.ServerVariables("REMOTE_ADDR")
  62.         End IF
  63.  
  64.         strSQL = strSQL & "')"
  65.  
  66. Application.Lock
  67. dcnDB.Execute strSQL
  68. strSQL = "SELECT Max(VisitorID) FROM Visitors"
  69. Set rsData = dcnDB.Execute(strSQL)
  70. Response.Cookies("VisitorID") = rsData(0)
  71. Application.Unlock
  72.  
  73. rsData.Close
  74.  
  75. End Sub
  76.  
  77. Sub RecordSearchInfo(dcnDB, strSearch, strSearch1, strSearch2, strSearch3, searchMemID, lngResultCount)
  78.     On Error Resume Next
  79.     Dim strSQL
  80.  
  81.     CreateVisitorID dcnDB
  82.  
  83.     strSQL = "INSERT INTO VisitorSearches " & "(VisitorID, SearchTerms, SearchTerms1, SearchTerms2, SearchTerms3, MemID, SearchResults) VALUES (" & Request.Cookies("VisitorID") & ", '" & Replace(strSearch, "'", "''") & "' , '" & Replace(strSearch1, "'", "''") & "', '" & Replace(strSearch2, "'", "''") & "', '" & Replace(strSearch3, "'", "''") & "', '" & Replace(searchMemID, "'", "''")& "', " & lngResultCount & ")"
  84.     dcnDB.Execute strSQL
  85.  
  86. End Sub
  87. %>
  88.  
  89. <%
  90. Sub MapRequestInfo (dcnDB, MapType, County)
  91.  
  92.     Dim strSQL
  93.  
  94.     CreateVisitorID dcnDB
  95.  
  96.     strSQL = "INSERT INTO MapRequests " & "(VisitorID, MapType, County) VALUES (" & Request.Cookies("VisitorID") & ", '" & Replace (MapType, "'", "''") & "' , '" & Replace(County, "'", "''") & "'" & ")"
  97.  
  98.     dcnDB.Execute strSQL
  99.  
  100. End Sub
  101.  
  102. %>
  103.  
Feb 23 '08 #7

CroCrew
Expert 100+
P: 563
ACK!!

Hello simonruk1,

Can you please add code tags to your posts when posting code and indent code that is inside of If/Then, loops, subs, functions, and where there should be indentions? Please make more of an effort because your last two posts are too hard to read.

I would like to help but this is just too much.

Sorry~
Feb 25 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.