Vbscript
Vbscript
Function counter(x,y)
dim sum, prod
sum = x + y
prod = x * y
counter = "the sum is: " & sum & vbnewline & "and the product is: "
& prod
End function
The function name "counter" would then be misleading, though, would it not?
Vbscript BeginTrans/commit
'The next line starts a transaction
adoConn.BeginTrans
Set adoCmd = Server.CreateObject("ADODB.Command")
'I added this to give the command 45 seconds to execute.
adoCmd.CommandTimeout = 45
adoCmd.ActiveConnection = adoConn
adoCmd.CommandText = "sproc_RecalculateQuantities"
adoCmd.CommandType = adCmdStoredProc
adoCmd.Execute
Set colErrs=adoConn.Errors
If adoConn.Errors.Count <> 0 then
For Each objError In colErrs
'This is the error number for a timeout.
If objError.Number=-2147217871 Then
adoConn.RollbackTrans
Response.Write "The query timed out before finishing. Please try again."
timeout=True
adoConn.Errors.Clear
Exit For
End If
Next
End If
Set adoCmd = Nothing
If TotalErrors = o Then
Conn.CommitTrans
Else
Conn.RollbackTrans
End If
UPDATE Person
SET Address = 'Stien 12', City = 'Stavanger'
WHERE LastName = 'Rasmussen'
UPDATE dbo…
SET Address = 'Stien 12', City = 'Stavanger'
WHERE LastName = 'Rasmussen'
Error Handling
Err.Description (gives a description of the error) Err.Number (the error code that was
associated with the error) Err.Raise (initiates an error code) Err.Clear (clears the values of
the Err object – resetting all values)
<%
else
sql="DELETE FROM customers"
sql=sql & " WHERE customersID='" & cid & "'"
on error resume next
conn.Execute sql
if err<>0 then
response.write("No update permissions!")
else
response.write("Record " & cid & " was deleted!")
end if
end if
conn.close
%>