Print Page | Close Window

Exception occurred.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=444
Printed Date: 29 March 2026 at 10:53am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Exception occurred.
Posted By: skyworld
Subject: Exception occurred.
Date Posted: 23 February 2003 at 10:30am

can some one please help me with this code im trying to get here.. I am having it so when someone visits my site it checks for a ip and ads it to the database. I think my main problem here is my sql entry though because its made for if a ip already exists...

error '80020009'

Exception occurred.

/Default.asp, line 10

My code:

<!--#include virtual="include/database/connect.asp"-->
<%
'Ip logger/blocker
Dim IPADDRESS

IPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IPADDRESS = "" Then IPADDRESS = Request.ServerVariables("REMOTE_ADDR")
strSQL = "SELECT * From ip where ip like '" & IPADDRESS & "'"
rsportal.Open strSQL, adoCon
if rsportal("ip") = "" then
rsportal.AddNew
rsportal.Fields("ip") = IPADDRESS
rsportal.Fields("log") = "0"
rsportal.fields("lastvisit") = formatdate(strdate, 0) & " @ " & time()
rsportal.fields("blocked") = FALSE
rsportal.Update
else

Do while not rsportal.eof
rsportal("log") = rsportal("log") + 1
rsportal("lastvisit") = formatdate(strdate, 0) & " @ " & time()
loop

end if

if rsportal("blocked") = TRUE then
response.redirect "banned.asp"
else
%>
<META HTTP-EQUIV="REFRESH" CONTENT="3; URL=index.asp">
<%
end if
if rsportal("theme") = "" then
rsportal("theme") = "default"
%>
<link rel="stylesheet" href="theme/<%=rsportal("theme")%>/style.css" type="text/css">
<%
else
end if
Set rsportal = Nothing
%><!--#include virtual="include/database/disconnect.asp"-->




Replies:
Posted By: skyworld
Date Posted: 23 February 2003 at 10:31am

O sorry...

Connect:

<%
Dim adoCon   'Holds the Database Connection Object
Dim rsportal   'Holds the recordset for the records in the database
Dim SQL  'Holds the SQL query for the database
Dim dbloc
dbloc = "fpdb/sky.mdb"
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(dbloc)
Set rsportal = Server.CreateObject("ADODB.Recordset")
%>

 

Disconnect:

<%
Set adoCon = Nothing
%>

 



Posted By: MadDog
Date Posted: 23 February 2003 at 12:19pm

this isnt the problem but you should close your connections all the way

<%
rsPortal.Close
Set rsportal = Nothing
adoCon.Close
Set adoCon = Nothing
%>



-------------
http://www.iportalx.net" rel="nofollow">


Posted By: skyworld
Date Posted: 23 February 2003 at 12:56pm

ok



Posted By: skyworld
Date Posted: 23 February 2003 at 1:04pm
i think the problem is that i have the sql querry looking for a record that has not been created yet... How do i create it if its not there?


Posted By: skyworld
Date Posted: 23 February 2003 at 1:09pm

btw this is line 10 i think...

if rsportal("ip") = "" then



Posted By: skyworld
Date Posted: 23 February 2003 at 6:22pm

i managed to get it to add and update but the problem i am getting now is it doesnt update to that field instead it adds it again. ...

 

my new code :)

 

<%
Dim adoCon   'Holds the Database Connection Object
Dim rsportal   'Holds the recordset for the records in the database
Dim SQL  'Holds the SQL query for the database
Dim dbloc
dbloc = "fpdb/sky.mdb"
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(dbloc)
'-------------------------------------------------------------------------------------
'IP LOGGER
Dim ipaddress
ipaddress = request.servervariables("http_x_for")
if ipaddress <> "" then
ip = ipaddress
else
ip = request.servervariables("remote_addr")
end if
if len(ip) > 0 then
Set rsportal = Server.CreateObject("ADODB.Recordset")
strsql = "select * from ip;"
rsportal.CursorType = 2
rsportal.LockType = 3
rsportal.open strsql, adocon

rsportal.addnew
rsportal.fields("ip") = ip
rsportal.fields("log") = "1"
rsportal.fields("lastvisit") = now()
rsportal.fields("blocked") = false
rsportal.fields("theme") = "default"
rsportal.update
end if
if err.number <> 0 then
strsql = "select * from ip where ip like '" & ip & "'"
rsportal.open strsql, adocon
rsportal("log") = rsportal("log") + 1
rsportal("lastvisit") = now()
end if
if rsportal("blocked") = true then
response.redirect "banned"
else
%>
<meta http-equiv="refresh" content="3; url=index.asp">
<link rel="stylesheet" href="theme/<%=rsportal("theme")%>/style.css" type="text/css">
<%
end if
rsportal.close
adoCon.Close
set rsportal = nothing
Set adoCon = Nothing
%>



Posted By: skyworld
Date Posted: 23 February 2003 at 6:24pm

pretty much it ads it instead of checking if its there and updating ...




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net