Database lukker forkert
Hej AlleDenne fil anvendes på vores hjemmeside, men jeg har fået at vide, at grunden til, at der ofte er fejl, skyldes - at der åbnes en database-forbindelse, men at den ikke lukkes korrekt !!
Er der nogen der kan finde denne fejl og rette den ???
Tusind Tak
....og fortsat god aften ;-)
<%
'###################################################
'# Setup
'###################################################
' // Virtuel Path. (Where the files are located)
'PollFilePath="poll/"
PollFilePath="udvidelser/newsandpoll/poll/"
'PollFilePath="http://www.asgi.dk/udvidelser/newsandpoll/poll/"
' // Admin Password
pollAdminModePassword = "Admin"
'Do NOT change the next line
if request("AdminMode")=pollAdminModePassword then PollFilePath=""
'pollDBLocation. Where the database is located
pollDBLocation=server.mappath(PollFilePath&"../../../db/poll.mdb")
' // PollDebug Mode.
' // if true = Show Error Msg if any Errors. And don't set the cookie date to now + 356days
' // Notice that there is very limited errorhandling.
pollDebug=false
' ####################
' ## Look and feel ##
' ####################
' // pollBgImage : Used for background color.
pollBgImage = "474971.gif"
' // pollGraphImage : Used for graph bars.
pollGraphImage = "215D84.gif"
' // pollLinesImage : Used for thin lines.
pollLinesImage = "215D84.gif"
' // pollLinesEnabled : Show thin lines or not. Set to true/false.
pollLinesEnabled = true
' // pollFont : Used for text
pollFont = "<font face=""Verdana"" color=""#000000"" size=""1"">"
' // pollHeading : Heading for the poll.
' // Use a image to make it look nice, otherwise uncomment the other line and change the text and/or font
'pollHeading = "<img src="""&PollFilePath&"images/poll_text.gif"">"
pollHeading = "<u><b><font color=""#FFFFFF"" face=""Verdana"" size=""2"">ASGI afstemning</font></b></u>"
'Should the "Total votes" text be shown to users. Set to true or false
pollShowTotalVotes = true
'#####################################################################
'## Text used in script. Change this to your own words/Language ##
'#####################################################################
pollTxtTotalVotes="Stemmer ialt"
'###################################################
'# Start
'###################################################
dim pollDB,pollRS,pollConstr
dim QID,sQuestion,ShowResultflag
set pollDB=server.createobject("ADODB.Connection")
set pollRS=server.createobject("ADODB.Recordset")
pollConstr = "Provider=MICROSOFT.JET.OLEDB.4.0; Data Source="&pollDBLocation
' // Get active QID and Question from database Question //
FinPollOpenDB()
if request("QID")<>"" then
QID=request("QID")
pollRS.open "select * from Questions where QID="&cstr(QID),pollDB,1,2
else
pollRS.open "select * from Questions where Active=1",pollDB,1,2
end if
if not (pollRS.bof and pollRS.eof) then
if QID="" then
QID=pollRS("QID")
end if
sQuestion=pollRS("Question")
else
call DBProcessError("Error : Could not find active poll")
end if
pollRS.close
pollDB.close
'Get the cookie
cookieContent = request.cookies("FinPol" & cstr(QID)&sQuestion)
' // See what we should do
if (cookieContent<>"" OR request("AdminMode")=pollAdminModePassword) then
'Cookie is set = vote has already been cast OR Admin mode
'So show the result
call ShowResult()
elseif (cookieContent="" and request.form("finPollOption")<>"") then
'Vote has been cast and cookie is empty
call CastVote()
else
'Show the poll
call ShowPoll()
end if
' // Cleanup
set pollRS=nothing
set pollDB=nothing
' // The End
'############################################
'# CastVote()
'# Update database with vote and set cookie
'############################################
function CastVote()
answer=request.form("finPollOption")
FinPollOpenDB()
pollRS.open "select * from Poll where QID="&cstr(QID),pollDB,3,3,1
if not (pollRS.bof and pollRS.eof) then '// The poll ID is OK //
'Update database
pollRS.find ("AnID = "+cstr(answer))
pollRS("Answer")=pollRS("Answer")+1
pollRS.update
'// set a cookie for this poll //
'// first clear the response object
response.clear
response.cookies("FinPol" & cstr(QID)&sQuestion)=Answer
if pollDebug<>true then
response.cookies("FinPol" & cstr(QID)&sQuestion).expires=Date + 365
end if
else
call DBProcessError("A poll with ID No."+cstr(QID)+" could not been found.")
end if
pollRS.close
pollDB.close
'Cleanup since we are doing a redirect
set pollRS=nothing
set pollDB=nothing
'// Redirect the user using ?prd=1 so Netscape don't throw up a object moved error//
Response.redirect(Request.ServerVariables("SCRIPT_NAME")&"?prd=1&"&request("QueryStringBackup"))
end function
'############################################
'# ShowPoll()
'# Show the poll
'############################################
function ShowPoll()
FinPollOpenDB()
pollRS.open "select * from Poll where QID="+cstr(QID)+" order by AnID",pollDB,1,1
if not (pollRS.bof and pollRS.eof) then
%>
<table border="0" cellspacing="0" width="250">
<tr>
<td width="100%" background="<%=PollFilePath%>images/<%=pollBgImage%>"><form method="POST" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<input type="hidden" value="<%=cstr(QID)%>" name="fQID">
<input type="hidden" value="<%=Request.QueryString%>" name="QueryStringBackup">
<table border="0" cellspacing="0" width="250" background="<%=PollFilePath%>images/ffffff.gif">
<tr>
<td colspan="3" background="<%=PollFilePath%>images/<%=pollBgImage%>" width="250" align="center"><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=3><br><%=pollHeading%><br><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=3></td>
</tr>
<tr>
<td width="4" valign="top" align="left"> </td>
<td valign="top" align="left" colspan="2" width="246"><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=3><b><%=pollFont%><br><%=sQuestion%><br></font></b><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=3></td>
</tr>
<% if (pollLinesEnabled=true) then%>
<tr>
<td width="250" valign="top" align="center" colspan="3"><img src="<%=PollFilePath%>images/<%=pollLinesImage%>" height=1 width=95%></td>
</tr>
<% end if%>
<%
while not pollRS.eof
i=i+1
%>
<tr>
<td width="4" valign="top" align="left"> </td>
<td width="12" valign="top" align="left"><input type="radio" value="<%=cstr(i)%>" name="finPollOption"></td>
<td valign="top" align="left" width="124"><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=3><%=pollFont%><br>
<%=pollRS("AnswerText")%></font></td>
</tr>
<%
pollRS.movenext
wend
%>
<tr>
<td width="250" valign="top" align="left" colspan="3"><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=1></td>
</tr>
<% if (pollLinesEnabled=true) then%>
<tr>
<td width="250" valign="top" align="center" colspan="3"><img src="<%=PollFilePath%>images/<%=pollLinesImage%>" height=1 width=95%></td>
</tr>
<% end if%>
<tr>
<td width="4" valign="top" align="left"> </td>
<td width="12" valign="top" align="left"> </td>
<td valign="top" align="right"><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=1><br><input type="submit" value="Stem" name="Submit" style="font-family: Verdana; font-size: 8pt; font-weight: bold"><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=10><br>
<img src="<%=PollFilePath%>images/spacer.gif" height=5 width=1></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
<%
end if
pollRS.close
pollDB.close
end function
'############################################
'# ShowResult()
'# Show the poll
'############################################
function ShowResult()
FinPollOpenDB()
pollRS.open "select * from Poll where QID="+cstr(QID),pollDB,1,1,1
if not (pollRS.bof and pollRS.eof) then
set rsTotal=server.createobject("ADODB.Recordset")
rsTotal.open "Select sum (Answer) from Poll where QID="+cstr(QID), pollDB, 1,1,1
total=rsTotal(0)
rsTotal.close
set rsTotal=nothing
i=0
pollRS.movefirst
%>
<table border="0" cellspacing="0" width="250">
<tr>
<td width="100%" background="<%=PollFilePath%>images/<%=pollBgImage%>"><form method="POST" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<input type="hidden" value="<%=cstr(QID)%>" name="fQID">
<table border="0" cellspacing="0" width="250" background="<%=PollFilePath%>images/ffffff.gif">
<tr>
<td colspan="3" background="<%=PollFilePath%>images/<%=pollBgImage%>" width="250" align="center"><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=3><br><%=pollHeading%><br><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=3></td>
</tr>
<tr>
<td width="4" valign="top" align="left"> </td>
<td valign="top" align="left" colspan="2" width="246"><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=3><b><%=pollFont%><br><%=sQuestion%><br></font></b><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=3></td>
</tr>
<% if (pollLinesEnabled=true) then%>
<tr>
<td width="250" valign="top" align="center" colspan="3"><img src="<%=PollFilePath%>images/<%=pollLinesImage%>" height=1 width=95%></td>
</tr>
<% end if%>
<%
while not pollRS.eof
i=i+1
%>
<tr>
<td width="4" valign="top" align="left"><img src="<%=PollFilePath%>images/spacer.gif" height=5 width=4></td>
<td width="6" valign="top" align="left"><%=pollFont%>·</font></td>
<td width="240" valign="top" align="left"><%=pollFont%>
<b><%=pollRS("AnswerText")%></b><br><%=calculate(pollRS("Answer"),Total)%> <%if ToTal<>0 then Response.write(formatpercent(pollRS("Answer")/Total,0))%>
<%
if request("AdminMode")=pollAdminModePassword then
response.write("<br>"&cstr(pollRS("Answer"))& " Votes")
end if
TotalVotes=TotalVotes+cInt(pollRS("Answer"))
%>
</font>
</td>
</tr>
<%
pollRS.movenext
wend
%>
<tr>
<td width="250" valign="top" align="left" colspan="3"><img src="<%=PollFilePath%>images/spacer.gif" height=3 width=100%></td>
</tr>
<% if (pollShowTotalVotes=true OR request("AdminMode")=pollAdminModePassword) then %>
<% if (pollLinesEnabled=true) then%>
<tr>
<td width="250" valign="top" align="center" colspan="3"><img src="<%=PollFilePath%>images/<%=pollLinesImage%>" height=1 width=95%></td>
</tr>
<% end if%>
<tr>
<td width="250" valign="top" align="center" colspan="3"><%=pollFont%><%=pollTxtTotalVotes%> : <%=TotalVotes%></font></td>
</tr>
<% end if %>
</form>
</table>
</td>
</tr>
</table>
<%
end if
pollRS.close
pollDB.close
end function
'############################################
'# DBProcessError(pollDebugmsg)
'# pollDebugmsg = What msg to display
'############################################
function DBProcessError(pollDebugmsg)
if pollDebug=true then
Response.write(pollDebugmsg)
end if
end function
'############################################
'# FinPollOpenDB()
'# Open database, show error if any problems
'############################################
sub FinPollOpenDB()
On ERROR Resume next
pollDB.open pollConstr ', "Admin",""
if Err.number<>0 then
Response.write("FinPoll Error : Could not open DataBase, make sure PollFilePath are set correctly.")
Response.end
end if
ON ERROR GOTO 0
end sub
'############################################
'# Calculate(Result, total)
'# returns a string containg several img tags for displaying .gif images,
'# which represent the graph bar
'############################################
Function Calculate(Result, total)
Const Max = 12 '// maximum length of the result bar as no. of gif images //
DIM sGif
sGif = "<img src="""&PollFilePath&"images/"&pollGraphImage&""" height=""9"" width=""6"">"
Dim NX, i, sRes
sRes = ""
if total = 0 then total=result
if total <>0 then
NX = Int(Result / total * Max + 0.5)
For i = 1 To NX
sRes = sRes + sGif
Next
end if
Calculate = sRes
End Function
%>
