Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MTS 1

Status
Not open for further replies.

athreya

Programmer
Apr 23, 2001
2
IN
I am not able to rollback the transaction. Need help.
 

Tell me some more info...


Are you using VB or ASP?

What is the database?

Are you calling the SetAbort method?

Let me know...

Kevin...
 
I am using MTS/VB/ASP with SQL Server 7.0.
I tried setabort method but i am not able to roll back.
If u have a sample code it will be helpful.


Athreya
 
A,

Here is a sample of 2 ASP pages wrapped in one transaction. ASP 1 calls ASP 2.
The @TRANSACTION directive on each page ties the results of each page into 1 transaction.
We will commit the transaction first, then abort the transaction, effectively
rolling back the transaction.

Let me know if you have other questions..

Kevin...


ASP Page 1

<% @ LANGUAGE=VBScript TRANSACTION=REQUIRED%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>&nbsp;Starting here</P>
<P>&nbsp;</P>
<%dim i

if objectcontext is nothing then
response.write(&quot;no object context&quot;)
Response.End
end if

'Execute the code on page 2 all wrapped in one transaction
Response.Write (&quot;Going to Page 2<BR>&quot;)

'server.execute or server.transfer is an IIS5 command
server.execute &quot;Page2.asp&quot;

Response.Write (&quot;Back from Page 2<BR>&quot;)

'Even though we committed the trans in page 2, this setabort should rollback the
'transaction
objectcontext.setabort

%>

</BODY>
</HTML>
<%

' Called if the transaction succeeds

Sub OnTransactionCommit()
Response.Write &quot;<hr />&quot;
Response.Write &quot;<p><strong>Page 1 Transaction Committed</strong></p>&quot;
End Sub

Sub OnTransactionAbort()
Response.Write &quot;<hr />&quot;
Response.Write &quot;<hr />&quot;
Response.Write &quot;<p><strong>Page 1 Transaction Aborted</strong></p>&quot;
End Sub
%>


ASP Page 2


<% @ LANGUAGE=VBScript TRANSACTION=REQUIRED %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<%
Dim conn, rs

set conn = server.CreateObject(&quot;ADODB.Connection&quot;)
set rs = server.CreateObject(&quot;ADODB.Recordset&quot;)
if conn is nothing then
Response.Write(&quot;conn nothing&quot;)
response.end
end if
Set rs = CreateObject(&quot;ADODB.Recordset&quot;)
if rs is nothing then
Response.Write(&quot;rs nothing&quot;)
response.end
end if
'using an oracle database
'replace with your connect string

conn.connectionstring = &quot;provider=MSDAORA.1;user id=xxx;password=xxx;data source=xxx;&quot;
conn.open

'replace with your update command
st = &quot;update otchfile set OTCHCHGTYP = 'Changed' where otchcrtcod = 'A' and otchcasnbr = '200205' &quot;
rs.open st, conn

Set conn = nothing
Set rs = nothing

'Here, inside the called page, the transaction will commit
ObjectContext.SetComplete

%>

</BODY>
</HTML>
<%
' Called if the transaction succeeds
Sub OnTransactionCommit()
Response.Write &quot;<hr />&quot;
Response.Write &quot;<p><strong>Page 2-Transaction Committed</strong></p>&quot;
End Sub

' Called if the transaction fails
Sub OnTransactionAbort()
Response.Write &quot;<hr />&quot;
Response.Write &quot;<p><strong>Page 2-Transaction Aborted</strong></p>&quot;
End Sub
%>

 
Thats fantastic Kevin.. Thank you.

It helped me too, albeit in a different way...

Thanks!

RR


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top