asp页面的事务提交问题
代码如下:
sub panduan()
if conn.Errors.Count>0 then '检查是否出错
conn.Errors.Clear '清楚出错
conn.RollBackTrans '如果插入数据操作失败,则事务向前回滚
response.Redirect "RegisterFail.html" '跳转页面
end if
end sub
if instr(session("flag"),"121")=0 then
response.write "<script>alert(""本页面为管理员专用,请登陆后进入。您没有管理本页面的权限。"");</script>"
response.write "<meta HTTP-EQUIV=REFRESH CONTENT='1; URL=../totheindex.htm'>"
response.end
end if
dim menuname,theurl
tmpmenu=split(menu(12,1),",")
menuname=tmpmenu(0)
theurl=tmpmenu(1)
'response.End()
'合同基本信息
productid=trim(request("productid"))
userid=trim(request("userid"))
cardlistid=trim(request("cardlistid"))
amount=trim(request("amount"))
Beneficiary=trim(request("Beneficiary"))
if userid="" then
msg="用户参数错误"
call error1(msg)
end if
'产品名称
if productid="" then
msg="请选择产品"
call error1(msg)
else
set rs=conn.execute("select * from product where hot=1 and productid="&productid)
if rs.eof then
msg="请查看是否有该产品,或许该产品是否是热销产品"
call error1(msg)
else
StartTime=rs("StartTime") '成立日期
productname=rs("productname")
PreContract=rs("PreContract")'合同前缀号
end if
rs.close
set rs=nothing
end if
'用户名字
set rs=conn.execute("select * from user1 where userid="&userid)
if rs.eof then
msg="请查看是否有该用户"
call error1(msg)
else
username=rs("username")
userclass=rs("userclass")
nickname=rs("nickname")
if userclass=1 then
set rs_1=conn.execute("select * from Individual where userid="&userid)
if not rs_1.eof then
cno=rs_1("cno")
end if
rs_1.close
set rs_1=nothing
elseif userclass=2 then
set rs_1=conn.execute("select * from Organization where userid="&userid)
if not rs_1.eof then
cno=rs_1("cno")
end if
rs_1.close
set rs_1=nothing
end if
end if
rs.close
set rs=nothing
if amount="" then
msg="购买数量不能为空"
call error1(msg)
end if
'是否低于最低购买量
set rs=conn.execute("select atlow,extent from product where productid="&productid)
if not rs.eof then
if clng(amount)<clng(rs("atlow")) then
msg="请仔细查看该产品的最低限额"
call error1(msg)
else
if rs("extent")<>"" then
temp=(amount/rs("extent"))
if instr(temp,".")>0 then
msg="请购买的分量为"&rs("extent")&"倍数增加"
call error1(msg)
end if
end if
end if
else
msg="请查看是否有该产品"
call error1(msg)
end if
rs.close
set rs=nothing
if cardlistid="" then
msg="请选择银行卡账号"
call error1(msg)
end if
'信用卡号
set rs=conn.execute("select * from cardlist where cardlistid="&cardlistid)
if rs.eof then
msg="请查看是否存在这个银行卡账号"
call error1(msg)
else
cardno=rs("cardno")
end if
rs.close
set rs=nothing
'启动事务:
Conn.BeginTrans
'产生合同流水号,格式是6位数目,例如:000001
'先去查找是否有删除的合同号,表:delContract
set rs_7=conn.execute("select * from delcontract where productid="&productid&" order by id ")
if rs_7.eof then
sql="select top 1 * from contract where productid="&productid&" order by ContractID desc"
'response.Write(sql)
'response.End()
set rs_1=conn.execute(sql)
if rs_1.eof then
listid="000001"
else
temp=rs_1("listid")
delid=rs_1("contractid")
'response.Write(temp)
'response.End()
temp=clng(temp)+1
lenght=len(temp)
for i=1 to 6-lenght
j=j&"0"
next
listid=cstr(j&cstr(temp))
end if
rs_1.close
set rs_1=nothing
else
listid=rs_7("listid")
id=rs_7("id")
'删除已经提取的合同号
conn.execute("delete delcontract where id="&id)
call panduan()
conn.execute("delete delcontract where productid="&productid&" and listid='"&listid&"'")
call panduan()
end if
rs_7.close
set rs_7=nothing
'合同日期
updatetime=now()
startyear=trim(request("startyear"))
'没有输入
if startyear="" or not isnumeric(startyear) then
'成立日期是否为空
if StartTime="" or StartTime="1900-1-1" then
updatetime=now()
else
updatetime=StartTime
end if
else
if len(StartYear)<4 then
msg="合同日期格式不对"
call error(msg)
else
temptime=StartYear&"-"&request("Startmonth")&"-"&request("Startday")
updatetime=cdate(temptime)
end if
end if
' response.Write(CardlistID)
' response.End()
set rs=conn.execute("select * from contract where cardlistid="&cardlistid&" and productid="&productid&" and userid="&userid&" and Beneficiary='"&Beneficiary&"' and amount="&amount&" ")
if not rs.eof then
contractid=rs("contractid")
else
'response.Write("111111111")
'写入数据
SET Rs=Server.CreateObject("ADODB.Recordset")
Sql="Select * From contract"
Rs.Open Sql,Conn,3,3
Rs.Addnew
rs("CardlistID")=CardlistID
rs("productid")=productid
rs("userid")=userid
if Beneficiary<>"" then
rs("Beneficiary")=Beneficiary
else
rs("Beneficiary")=nickname
end if
rs("amount")=amount
rs("ListID")=ListID '流水号
Rs("updatetime")=updatetime
rs("adminid")=session("userid")
rs("flag")=0
rs.Update
Rs.close
Set Rs=Nothing
call panduan()
money=""
'更新用户级别
set rs2=conn.execute("select sum(amount) as money from contract where userid="&userid&" and flag<>3")
if not rs2.eof then
money=rs2("money")
if money<>"" then
set rs3=conn.execute("select * from groupuser order by groupid desc")
if not rs3.eof then
do while not rs3.eof
if clng(money)>= clng(rs3("amount")) then
usergroup=rs3("groupid")
exit do
end if
rs3.movenext
loop
if userclass<>"" then
conn.execute("update user1 set usergroup="&usergroup&" where userid="&userid&"")
call panduan()
end if
end if
rs3.close
set rs3=nothing
end if
end if
rs2.close
set rs2=nothing
'提交事务
Conn.CommitTrans
错误提示:
Microsoft OLE DB Provider for SQL Server 错误 '80004005'
不能在手动或分布事务方式下创建新的连接。
实在不知道到底哪里出了问题了