469,086 Members | 1,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

375 256MB
Hello
I am using Asp.net with VC# having backend SQL SERVER
I have written a procedure in sqlserver as below.
It does not throw any error in sqlserver.

This is the procedure

Expand|Select|Wrap|Line Numbers
  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. GO
  4. ALTER procedure [dbo].[updatecommand]
  5. as
  6. declare @speed int
  7. declare @ignition int
  8. declare @basestationname varchar(50)
  9. declare @registrationno varchar(50)
  10. declare @exp int 
  11. set @exp=null
  12.  
  13. begin
  14. declare opencur cursor for 
  15. select registrationno,speed,ignition,basestationname from gpsdata where datediff(mi,gps_datetime,getdate())>10 order by gps_datetime
  16. end
  17.  
  18. open opencur
  19.  
  20. fetch next from opencur into @registrationno,@speed,@ignition,@basestationname
  21. WHILE (@@FETCH_STATUS = 0)
  22. begin
  23. if(@speed<>0 or @ignition<>0 or @basestationname<>null)
  24. begin Tran 
  25.     update gpsdata set speed=0,ignition=0,basestationname=null where registrationno=@registrationno
  26.     set @exp=@@error
  27.     if (@exp<>null)
  28.         rollback Tran
  29.     else
  30.     begin
  31.         update gpsdata_history set speed=0,ignition=0,basestationname=null where registrationno=@registrationno
  32.         set @exp=@@error
  33.         if(@exp<>null)
  34.              rollback Tran
  35.  
  36.     end
  37.  
  38. fetch next from opencur into @registrationno,@speed,@ignition,@basestationname
  39.  
  40.             commit Tran
  41.  
  42. end
  43. close opencur
  44. deallocate opencur
But when i execute the above procedure in asp.net i get the error
Commit Transaction has no corresponding Begin Tranasaction

This is code for asp.net
Expand|Select|Wrap|Line Numbers
  1. MyCon.Open();      
  2.         SqlCommand MyCmd = new SqlCommand("updatecommand", MyCon);
  3.         MyCmd.CommandType = CommandType.StoredProcedure;
  4.         MyCmd.ExecuteNonQuery();
  5.         MyCon.Close();
Kindly help
Regards
cmrhema
Sep 5 '07 #1
0 3342

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by DP | last post: by
1 post views Thread by anders_tung | last post: by
11 posts views Thread by Markus Breuer | last post: by
3 posts views Thread by Alberto | last post: by
3 posts views Thread by Peter Kirk | last post: by
1 post views Thread by Horace | last post: by
2 posts views Thread by Jim Wilson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.