Script overbelaster db
Jeg har følgende kode i et "spil" jeg er ved at lave, men hver gang denne kode bliver brugt så går IIS ned, eller helt nøjagtigt, denne åbner begge databaser og kan ikke finde ud af at lukke dem igen, og så fryser siden.Er der en der lige kan se hvor problemet kunne ligge? Jeg ved ikke helt hvilke oplysninger i ellers har brug for, men i skal være velkommen til at spørge.
Håber i kan hjælpe og på forhånd tak.
manualfodder = Onlynumbers(Request.Querystring("givepigfodder"))
If manualfodder > 0 Then
strSQL = "SELECT * From game_pigstable where gpigID=" & manualfodder & " AND gpigFarmID=" & Session("activefarm") & " AND IsNull(gpigSellDate) AND gpigPigWeightEnd < " & SITE_LOCAL_PIGSELLWEIGHT & " AND gpigDailyFodderMissing>0 AND gpigReadyForSale=false"
Else
strSQL = "SELECT * From game_pigstable where gpigFarmID=" & Session("activefarm") & " AND gpigLastFeed < Now()-1 AND IsNull(gpigSellDate) AND gpigPigWeightEnd < " & SITE_LOCAL_PIGSELLWEIGHT & " AND gpigReadyForSale=false Order By gpigLastFeed"
End If
Set rsPigs = ConnPigstable.Execute (strSQL)
If not (rsPigs.EOF OR rsPigs.BOF) Then
Do
lastfeedday = rsPigs("gpigLastFeed")
continuescript = true
Do While Dateadd("d",1,lastfeedday) < Now() AND continuescript = true
lastfeedday = Dateadd("d",1,lastfeedday)
Randomize
fodderusepig = (SITE_LOCAL_PIGFODDERUSEDAYMAX-SITE_LOCAL_PIGFODDERUSEDAYMIN+1)*rnd+SITE_LOCAL_PIGFODDERUSEDAYMIN
fodderneeded = rsPigs("gpigGroupSizeEnd")*fodderusepig
manuremade = (SITE_LOCAL_PIGMANUREMAX-SITE_LOCAL_PIGMANUREMIN+1)*rnd+SITE_LOCAL_PIGMANUREMIN
totalmanuremade = rsPigs("gpigGroupSizeEnd")*manuremade
piggrowth = (SITE_LOCAL_PIGGROWTHDAYMAX-SITE_LOCAL_PIGGROWTHDAYMIN+1)*rnd+SITE_LOCAL_PIGGROWTHDAYMIN
If Clng(rsPigs("gpigPigWeightEnd")+piggrowth) >= Clng(SITE_LOCAL_PIGSELLWEIGHT) Then
strSQL = "SELECT * From log_prices where upDate=" & Formatdatetime(lastfeedday,vbshortdate) & ""
Set rsPrice = ConnMain.Execute (strSQL)
If not (rsPrice.EOF OR rsPrice.BOF) Then
readyforsale = "true"
pigprice = rsPrice("upPigSellPrice")
Else
readyforsale = "false"
pigprice = 0
End If
rsPrice.Close
set rsPrice = Nothing
Else
readyforsale = "false"
pigprice = 0
End If
If Clng(SITE_FARM_TOTALPIGFODDERAMOUNT) >= Clng(fodderneeded) Then
continuescript = true
SITE_FARM_TOTALPIGFODDERAMOUNT = Clng(SITE_FARM_TOTALPIGFODDERAMOUNT-fodderneeded)
SITE_FARM_MANURE = Clng(SITE_FARM_MANURE+totalmanuremade)
strSQL2 = "Update game_pigstable set "
strSQL2 = strSQL2 & "[gpigPigWeightEnd]=[gpigPigWeightEnd]+" & Replace(piggrowth, ",", ".") & ", "
strSQL2 = strSQL2 & "[gpigSellPrice]=" & Replace(pigprice, ",", ".") & ", "
strSQL2 = strSQL2 & "[gpigFodderUseTotal]=[gpigFodderUseTotal]+" & Replace(fodderneeded, ",", ".") & ", "
strSQL2 = strSQL2 & "[gpigDailyFodderMissing]=0, "
strSQL2 = strSQL2 & "[gpigLastFeed]='" & ConvertDate(lastfeedday) & "', "
strSQL2 = strSQL2 & "[gpigReadyForSale]=" & readyforsale & " "
strSQL2 = strSQL2 & "where gpigFarmID=" & Session("activefarm") & " AND gpigID=" & rsPigs("gpigID") & " "
ConnPigstable.Execute(strSQL2)
strSQL2 = "Update game_gamefarms set "
strSQL2 = strSQL2 & "[faManure]=[faManure]+" & Replace(totalmanuremade, ",", ".") & " "
strSQL2 = strSQL2 & "where faID=" & Session("activefarm") & " "
ConnMain.Execute(strSQL2)
strSQL = "SELECT game_buildings.*, game_buildings_users.* FROM game_buildings_users INNER JOIN game_buildings ON game_buildings_users.usbldBuildingID = game_buildings.bldID WHERE usbldFarmID=" & Session("activefarm") & " AND usbldStoredProduct='pigfodder' Order by usbldStored"
Set rsFodder = ConnMain.Execute(strSQL)
If Not (rsFodder.EOF OR rsFodder.BOF) Then
Do While Not Clng(fodderneeded) = 0
If Clng(rsFodder("usbldStored")) >= Clng(fodderneeded) Then
strSQL2 = "Update game_buildings_users set "
strSQL2 = strSQL2 & "[usbldStored]=[usbldStored]-" & Replace(fodderneeded, ",", ".") & " "
strSQL2 = strSQL2 & "where usbldID=" & rsFodder("usbldID") & " "
ConnMain.Execute(strSQL2)
fodderneeded = 0
Else
strSQL2 = "Update game_buildings_users set "
strSQL2 = strSQL2 & "[usbldStored]=0 "
strSQL2 = strSQL2 & "where usbldID=" & rsFodder("usbldID") & " "
ConnMain.Execute(strSQL2)
fodderneeded = fodderneeded-rsFodder("usbldStored")
End If
Loop
End If
rsFodder.Close
set rsFodder = Nothing
Else
continuescript = false
strSQL2 = "Update game_pigstable set "
strSQL2 = strSQL2 & "[gpigDailyFodderMissing]=" & Replace(fodderneeded, ",", ".") & " "
strSQL2 = strSQL2 & "where gpigFarmID=" & Session("activefarm") & " AND gpigID=" & rsPigs("gpigID") & " "
ConnPigstable.Execute(strSQL2)
End If
Loop
rsPigs.MoveNext
Loop While Not rsPigs.EOF
End If
rsPigs.Close
set rsPigs = Nothing