Hello everybody. Im using ASP to output WML pages. It worked fine so far, but Im trying to use transactions while inserting records to the database since in a single process I have to update a table and INSERT to 2 tables.
Here's my code:
(only part of the page)
I get the "No transaction is active" error. But when I check my database, the UPDATE statement has been executed. Any help?
Thanks.
Here's my code:
(only part of the page)
Code:
<%@ TRANSACTION=Required LANGUAGE="VBScript" %>
<!-- #Include File="cx.asp" -->
<%
Response.ContentType = "text/vnd.wap.wml"
Response.Expires = -1
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Cache-Control", "no-cache,must-revalidate"
If Session("login") <> "ok" Then
Response.Redirect "home.wml"
End If
Dim j_id
Dim r_id
Dim comments
Dim p_type
Dim p_id
Dim p_amount
Dim e_id
Dim c_id
Dim a_id
Dim strSql1
Dim strSql2
Dim strSql3
Dim strDate
e_id = Session("e_id")
j_id = Request.QueryString("j_id")
r_id = Request.QueryString("optRep")
comments = Request.QueryString("comments")
p_type = Request.QueryString("optPay")
p_id = Request.QueryString("receipt")
p_amount = Request.QueryString("amt")
%>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"[URL unfurl="true"]http://www.wapforum.org/DTD/wml_1.1.xml">[/URL]
<wml>
<card id="main" title="Processing">
<do type="accept" label="Jobs">
<go href="main.asp#jobs"/>
</do>
<%
If Len(r_id) = 0 Or Len(comments) = 0 Or Len(p_id) = 0 Or Len(p_amount) = 0 Or Not IsNumeric(p_amount) Then
Response.Write "Please fill in all information before processing<br>"
%>
<anchor title="Go"><go href="confirm.asp?j_id=<%=j_id%>"/>Back</anchor><br>
<%
Else
objRs.Open "Select a_id, c_id From job Where j_id = " & j_id,objCon,3,2
c_id = objRS("c_id")
objRs.Close
objRS.open "Select * From payment Where p_id='" & p_id & "'",objCon,3,2
on error resume Next
If objRs.Eof Then
strDate = Format(Now, "dd/mm/yyyy")
strSql1 = "UPDATE job SET status = 1 WHERE j_id = " & j_id
strSql2 = "Insert Into payment ('" & p_id & "', " & p_amount & ", " & strDate & ")"
strSql3 = "Insert Into jobdone (e_id, r_id, c_id, a_id, p_id, jd_comments, jd_date) Values (" & e_id & ", " & r_id & ", " & c_id & ", " & a_id & ", '" & p_id & "', '" & comments & "', " & strDate & ")"
objCon.beginTrans
objCon.Execute strSql1
objCon.Execute strSql2
objCon.Execute strSql3
If Err.Number <> 0 Then
objCon.RollBackTrans
objCon.close
Set objCon = Nothing
Response.write Err.Description
Else
objCon.CommitTrans
objCon.close
set objCon =Nothing
Response.write "Record updated successfully<br>"
end If
%>
I get the "No transaction is active" error. But when I check my database, the UPDATE statement has been executed. Any help?
Thanks.