Avatar billede tblaster Nybegynder
02. marts 2003 - 13:25 Der er 2 kommentarer og
1 løsning

Optimering af asp kode

Er der nogen der kan optimer min kode. Det tager alt for langtid at gennemløbe den. Nogle gange så langtid at den overskrider den tid den må køres på på serveren.

_________________________________________
<%
  If Not Session("auth_granted") = "true" Then
      Response.Redirect "../redirect.htm"
    Response.End
  End If
%>
<HTML>
<HEAD>
<TITLE>Booking af mødelokaler</TITLE>

</HEAD>
<style>
body {

    background : 000000;
    background-color: #FFFFFF;
    FONT-FAMILY: Tahoma, Arial, Verdana, Helvetica, sans-serif;
    FONT-SIZE: 8pt
    color: white;
    color: #000000;
    font-size: 10px;
    font-family: Tahoma;
   
    scrollbar-face-color: "#FFFFFF";
    scrollbar-shadow-color: "#FFFFFF";
    scrollbar-highlight-color: "#000000";
    scrollbar-3dlight-color: "#000000";
    scrollbar-darkshadow-color: "#000000";
    scrollbar-track-color: "#FFFFFF";
    scrollbar-arrow-color: "#000000";
   
}
    input, textarea, select, option {
        font-family: verdana;
        font-size: 10px;
        background: #FFFFFF;
        border:1px solid #111111;
        color: #000000;
}
TD
{
    COLOR: #000000; FONT-FAMILY: Times New Roman; FONT-SIZE: 12pt
}
SMALL
{
    FONT-SIZE: 8pt
}
A:link
{
    COLOR: #000033; TEXT-DECORATION: none
}
A:visited
{
    COLOR: #003333; TEXT-DECORATION: none
}
A:hover
{
    COLOR: #BFBFBF; TEXT-DECORATION: none
}
    </style>
<BODY text=#000000 vLink=#000000 aLink=#000000 link=#000000 rightMargin=0>
                  <TABLE cellSpacing=0 cellPadding=0 width=584 border=0>
                    <TBODY>
                    <TR>
                      <TD width=582 bgColor=#000000><IMG height=1 alt=""
                        src="../pics/Design/blank(1).gif"
                        width=582 border=0><BR></TD>
                      <TD width=2 bgColor=#ffffff><IMG height=1 alt=""
                        src="../pics/Design/blank(1).gif"
                        width=2 border=0><BR></TD></TR></TBODY></TABLE>
                  <TABLE cellSpacing=0 cellPadding=0 width=584 border=0 height="70">
                    <TBODY>
                    <TR>
                      <TD vAlign=top align=left width=1 bgColor=#000000
                      height=27><IMG height=25 alt="" src="../pics/Design/blank.gif"
                        width=1 border=0><BR></TD>
                      <TD vAlign=top align=left width=5 bgColor=#608EC6
                      height=27><BR></TD>
                      <TD align=left width=565 bgColor=#608ec6
                      height=27>
    <font color="#FFFFFF" style="font-size: 12pt" face="Arial"><b>Bookning</b></font><BR></TD>
                      <TD vAlign=top align=left width=8
                      background=../pics/Design/content_right_top.gif height=27><BR></TD></TR>
                    <TR>
                      <TD vAlign=top align=left width=1 bgColor=#000000 height="17"><IMG
                        height=1 alt="" src="../pics/Design/black.gif" width=1
                      border=0></TD>
                      <TD vAlign=top align=left width=10 bgColor=#CFDFFC height="17">&nbsp;</TD>
                      <TD vAlign=top align=left width=565 bgColor=#CFDFFC
                      height=17>
                        <br>
<%
'Slå fejl raportering fra:
On Error Resume Next

bodyTxt = bodyTxt & "Følgende reservation er registreret:"
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Lokale:" & vbTab & vbTab & vbTab & Session("Lokale")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Dato: " & vbTab & vbTab & vbTab & Session("Dato")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Initial: " & vbTab & vbTab & vbTab & Session("auth_Initial")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Navn: " & vbTab & vbTab & vbTab & Session("auth_Fornavn") & " " & Session("auth_Efternavn")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Firma: " & vbTab & vbTab & vbTab & Session("auth_Gruppenavn")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Tlf: " & vbTab & vbTab & vbTab & vbTab & Session("tlf")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Fra: " & vbTab & vbTab & vbTab & vbTab & Session("tid")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Til:& " & vbTab & vbTab & vbTab & Session("Slut")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Reservation: " & vbTab & vbTab &  Session("kommentar")
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Dato for bestilling: " & vbTab & Dato
bodyTxt = bodyTxt & VbCrLf
bodyTxt = bodyTxt & "Pris ialt kr: " & vbTab & vbTab & Session("Samletpris") & " (ekskl. moms)"
bodyTxt = bodyTxt & VbCrLf

If Session("sagsnr") <> "" then
  bodyTxt = bodyTxt & "Sagsnr \ medarbejdernr: " & Session("Sagsnr")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("Familiefest") >< "Ingen familiefest" Then
  bodyTxt = bodyTxt & "Familiefest: " & vbTab & vbTab & Session("Familiefest")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("antal") <> "" then
  bodyTxt = bodyTxt & "Antal: " & vbTab & vbTab & vbTab & Session("antal")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("Bordopstilling") <> "" then
  bodyTxt = bodyTxt & "Bordopstilling: " & vbTab & vbTab & Session("bordopstilling")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("Øl/vand") <> ""  Or Session("Kaffe/The") <> "" Or Session("kaffekande") <> "" Or Session("tekande") <> "" Or Session("Rundstykker") <> "" Or Session("ost") <> "" Or Session("Eftermiddagskage") <> "" Or Session("Småkager") <> "" Or Session("Frugt") <> "" Or Session("isvandkande") <> "" Or Session("opdækning_uden_dug") <> "" Or Session("opdækning_med_dug") <> "" Or Session("buffet") <> "" Or Session("andet") <> "" Or Session("foldevæg") <> "" Or Session("projektør") <> "" Then
  bodyTxt = bodyTxt & "Kantineydelser:"
  bodyTxt = bodyTxt & VbCrLf
end if
if Session("øl/vandantal") <> "" then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & "Antal Øl/vand: " & Session("øl/vandantal")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("Kaffe/The") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("Kaffe/The") & VbCrLf
end if
If Session("kaffekande") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("kaffekande") & VbCrLf
end if
if Session("kaffekandeantal") <> "" then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & "Antal kaffekander: " & Session("kaffekandeantal")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("tekande") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("tekande") & VbCrLf
end if
if Session("tekandeantal") <> "" then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & "Antal tekander: " & Session("tekandeantal")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("Rundstykker") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("Rundstykker") & VbCrLf
end if
If Session("ost") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("ost") & VbCrLf
end if
If Session("Eftermiddagskage") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("Eftermiddagskage") & VbCrLf
end if
If Session("Småkager") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("Småkager") & VbCrLf
end if
If Session("Frugt") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("Frugt") & VbCrLf
end if
If Session("isvandkande") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("isvandkande") & VbCrLf
end if
If Session("opdækning_uden_dug") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("opdækning_uden_dug") & VbCrLf
end if
If Session("opdækning_med_dug") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("opdækning_med_dug") & VbCrLf
end if
If Session("buffet") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("buffet") & VbCrLf
end if
if Session("buffetantal") <> "" then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & "Antal til buffet: " & Session("buffetantal")
  bodyTxt = bodyTxt & VbCrLf
end if
If Session("andet") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("andet") & VbCrLf
end if
If Session("foldevæg") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("foldevæg") & VbCrLf
end if
If Session("projektør") <> "" Then
  bodyTxt = bodyTxt & vbTab & vbTab & vbTab & vbTab & Session("projektør") & VbCrLf
end if

set JMail = server.createobject("JMail.SMTPMail")
JMail.sender = "Autosender@firma.dk"
JMail.SenderName = "Autosender"
JMail.subject = "Reservation af mødelokale"
JMail.AddRecipient "webmaster@firma.dk"
JMail.AddRecipient Session("auth_Email")
If Session("Familiefest") >< "Ingen familiefest" then
JMail.AddRecipient Session("DepositumMail")
end if
JMail.ContentType = "text/plain"
JMail.body = bodyTxt
JMail.priority = 1
JMail.maildomain = "mail.firma.dk"
JMail.silent = true
JMail.execute
JMail.close()

Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DBQ=" & Server.Mappath("../../db/Booking.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};Password=1234;"

sSQL = "SELECT * FROM booking"
rs.Open sSQL, Conn,1,3

startTid = Session("tid")
do while CDate(startTid) <= CDate(Session("Slut"))
  tider = tider & "," & formatdatetime(CDate(startTid),4)
  startTid = DateAdd("n",30,startTid) 
loop
if tider <> "" then tider = Mid(tider,2)

For EACH tid In Split(tider, ",")
    rs.AddNew
    rs("bookid") = session("booknr")
    rs("tid") = tid
    rs("dato") = Session("datobestil")
    rs("oprettet") = Dato1
    rs("lokalenr") = Session("Id")
    rs("firma") = Session("auth_Gruppenavn")
    rs("initialer") = Session("auth_Initial")
    rs("mail") = Session("auth_Email")
    rs("tlf") = Session("tlf")
    rs("kommentar") = Session("kommentar")
    rs("samletpris") = Session("Samletpris")
    rs("sagsnr") = Session("Sagsnr")
    rs("antal") = Session("antal")
    rs("bordopstilling") = Session("bordopstilling")
    rs("foldevæg") = Session("foldevæg")
    rs("projektør") = Session("projektør")
    rs("KaffeThe") = Session("Kaffe/The")
    rs("kaffekande") = Session("kaffekande")
    rs("kaffekandeantal") = Session("kaffekandeantal")
    rs("tekande") = Session("tekande")
    rs("tekandeantal") = Session("tekandeantal")
    rs("Rundstykker") = Session("Rundstykker")
    rs("ost") = Session("ost")
    rs("Eftermiddagskage") = Session("Eftermiddagskage")
    rs("Småkager") = Session("Småkager")
    rs("Frugt") = Session("Frugt")
    rs("isvandkande") = Session("isvandkande")
    rs("opdækning_uden_dug") = Session("opdækning_uden_dug")
    rs("opdækning_med_dug") = Session("opdækning_med_dug")
    rs("buffet") = Session("buffet")
    rs("buffetantal") = Session("buffetantal")
    rs("andet") = Session("andet")
    rs("fest") = Session("Familiefest")
    rs("Ølvand") = Session("Øl/vand")
    rs("Ølvandantal") = Session("øl/vandantal")
    rs.update

Next
   

'Tjek om der har være fejl
if err then
  Response.write "Det opstod en fejl på siden. Prøv at starte din bookning forfra."
else
  Response.write "Bookningen er registreret!"
end if


Set Conn = Server.CreateObject("ADODB.Connection")
        Set Rs = Server.CreateObject("ADODB.Recordset")
        Conn.Open "DBQ=" & Server.Mappath("../../db/Booking.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};Password=1234;"

    sSQL = "SELECT * FROM booknr"
    rs.Open sSQL, Conn,1,3
   
    rs.Update
    rs("Booknr") = rs("Booknr") + 1
    rs.Update
   
    rs.close
%>
            &nbsp;</TD>
                      <TD vAlign=top align=left width=8
                      background=../pics/Design/content_right_middle.gif
                        rowSpan=2 height="43">&nbsp;</TD></TR>
                    <TR>
                      <TD vAlign=bottom align=left width=564 bgColor=#CFDFFC
                      colSpan=3 height="26"><IMG height=26 alt=""
                        src="../pics/Design/newsitem_left_bottom.gif" width=56
                      border=0></TD></TR></TBODY></TABLE>
                  <TABLE cellSpacing=0 cellPadding=0 width=584 border=0>
                    <TBODY>
                    <TR>
                      <TD width=26 bgColor=#ffffff><IMG height=15 alt=""
                        src="../pics/Design/content_left_bottom.gif"
                        width=26 border=0><BR></TD>
                      <TD width=554 bgColor=#FFFFFF><IMG height=15 alt=""
                        src="../pics/Design/content_bottom.gif"
                        width=558 border=0><BR></TD>
                      <TD width=2 bgColor=#ffffff><IMG height=1 alt=""
                        src="../pics/Design/blank(1).gif"
                        width=2 border=0><BR></TD></TR></TBODY></TABLE>
               
</BODY></HTML>
Avatar billede mortrr Praktikant
02. marts 2003 - 13:36 #1
Der kan nok ikke gøres så meget ved koden, hvis du ikke laver om på din database.
Du gemmer de samme ting gentagne gange, med kun en ændring i tid. Flyt tiden ud i en separat tabel.

Men som et hurtigt fiks kunne du ændre Server.ScriptTimeout.
Den står som default til 90 (sekunder).

- Morten
Avatar billede tblaster Nybegynder
23. marts 2003 - 13:30 #2
Lukker
Avatar billede hnteknik Novice
27. august 2003 - 15:04 #3
Kan du ikke bare sætte din session.timeout op ???

Henrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester