asp页面的事务提交问题

ivy_ou 2003-12-15 12:03:15

代码如下:
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'

不能在手动或分布事务方式下创建新的连接。

实在不知道到底哪里出了问题了
...全文
64 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
begintrans一般放在连接打开之后,conn.open
committrans一般放在关系连接之前.就不会出错了.
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
错误是一样的
:"(
zorou_fatal 2003-12-15
  • 打赏
  • 举报
回复
把conn.begintrans放到最开头。
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
up
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
:(
楼上的.我的代码写得很差.
不过我也不是很懂什么代码规则什么的
可以指导一下么:(
诚心求教ing
Reker熊 2003-12-15
  • 打赏
  • 举报
回复
這代碼寫的啊...:)
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
支持啊.其他页面都没有问题 ,就是这个页面出现问题啊
billywg 2003-12-15
  • 打赏
  • 举报
回复
你的环境没问题吧。是否支持事务。
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
sql server数据库啊
zorou_fatal 2003-12-15
  • 打赏
  • 举报
回复
你用的是什么数据库啊 ?
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
楼上的,我不会存储过程
而且现在数据库不在我这里,我已经不能操作数据库,只能在页面上修过了:(
请帮我看看这里到底哪里有问题了?
wsqsoft 2003-12-15
  • 打赏
  • 举报
回复
你不如把它写成存储过程
ivy_ou 2003-12-15
  • 打赏
  • 举报
回复
你们好,谢谢你们帮忙,但是还是有问题
你们帮忙看看这个有什么问题
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")
if userclass=1 or userclass=2 then
sql="update user1 set usergroup="&usergroup&" where userid="&userid&""
'response.Write(sql)
'response.End()
conn.execute(sql)
call panduan() '调用事务判断的函数
end if
exit do
end if
rs3.movenext
loop
end if
rs3.close
set rs3=nothing
end if
end if
rs2.close
set rs2=nothing

这里的事务提交出错了,只要删除这个事务提交,那么整个页面就没有错,
错误提示是:
Microsoft OLE DB Provider for SQL Server 错误 '80004005'

不能在手动或分布事务方式下创建新的连接。

我不明白是不是我没有注意什么地方.请你们帮忙看看

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧