Classic ASP
ASP 에서 트랜젝션 처리
NJHouse
2014. 8. 3. 17:20
방법 1
set dbCon = Server.CreateObject("Adodb.Connection")
on Error resume next
dbCon.BeginTrans
strSql = " Insert Into [테이블1명] values("입력값")
dbCon.Execute(strSql)
errNum = errNum + dbCon.errors.Count
strSql = " Insert into [테이블2명] values("입력값1")
dbCon.Execute(strSql)
errNum = errNum + dbCon.errors.Count
strSql = " Insert into [테이블2명] values("입력값2")
dbCon.Execute(strSql)
errNum = errNum + dbCon.errors.Count
If errNum = 0 Then
dbCon.CommitTrans
response.write "트랜젝션 성공"
Else
dbCon.RollbackTrans
response.write "트랜젝션 실패"
End if
방법 2
set dbCon = Server.CreateObject("Adodb.Connection")
on Error resume next
dbCon.BeginTrans
strSql = " Insert Into [테이블1명] values("입력값")
dbCon.Execute(strSql)
strSql = " Insert into [테이블2명] values("입력값1")
dbCon.Execute(strSql)
strSql = " Insert into [테이블2명] values("입력값2")
dbCon.Execute(strSql)
If dbCon.errors.Count <> 0 Then
dbCon.errors.Clear
dbCon.RollbackTrans
response.write "트랜젝션 실패"
Else
dbCon.errors.Clear
dbCon.CommitTrans
response.write "트랜젝션 성공"
End if
주의 : "관리도구" - "서비스" 에 보면 Distributed Transaction Coordinator 항목이 동작하고 있어야함.
반응형