473,847 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

375 Contributor
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 3600

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

Similar topics

3
11634
by: DP | last post by:
Is there any command exists as "commit transaction" ? begin transaction < DML1 stmts > begin transaction < DML2 stmts > rollback transaction commit transaction which set of DML will be commites to the database or none ?
1
10063
by: anders_tung | last post by:
Hi, I have a procedure which will call 3 functions. First function will update a record. Second function will delete a record. Third function will insert a record. Each function will return a zero if successful, otherwise return 1. My questions are
11
12732
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to read the new date. So process B starts "select ..." but does not get the previously inserted row. The timespan between commit and select is very short. (NOTE: two different sessions are used) Questions: 1.) Does commit when returning from call...
3
6648
by: Alberto | last post by:
I've a complex stored procedure, that makes a lot of insert, update, delete and so on. I would like to make some commits durint this sp, but of course they are not "real" commit because who call the sp could decide for a rollback. But I know that this commit has to be real. In fact, the transaction log grows really too much during the execution.
3
3904
by: Peter Kirk | last post by:
Hi there when working with database connections in C# is there a concept of "auto commit"? For instance, if I obtain a database connection in java I can set the auto-commit state to true or false. Is there something similar in C#, or how do I handle this - do I always have to start and end transactions and commit database updates myself?
1
4414
by: Horace | last post by:
Hello I am writing an ASP.NET / SQL-Server application and wanting to know when to connect/begin-transaction and commit/disconnect. I have a common module which I call at the beginning of Page_Load which, when instantiated performs the connect/begin-transaction. The page then does what it has to do (eg when a Save button is clicked it will do a read/write to the database within the btnSave_Clicked event). At the end of the 'event'...
2
1906
by: Jim Wilson | last post by:
The debug logs seem a little confusing. On sending a query something like this will show up: DEBUG: StartTransactionCommand LOG: query: select * from blah; DEBUG: ProcessQuery DEBUG: CommitTransactionCommand This is with auto commit off. My first reaction on seeing this was the auto commit setting must not work. Then I noticed that most things, even "begin"
2
2234
by: Ryan | last post by:
I've re-written a stored procedure and when I post the following code into the existing SP in EM, is saves OK. However, when I re-edit the SP, the last line 'Commit Transaction' has been removed. I cannot save the remainder of the SP as it throws error 208 (Invalid Object name #Max) about two of the temp tables I use when I post the entire script. It shows in a message box with the header : 'Microsoft SQL-DMO(ODBC SQLState:42S02) I...
1
1503
by: Scott Cupstid | last post by:
We are working on a VB.NET application using SQLClient command objects to post data to the underlying SQL Server 2000 database. The application is deployed in a multi-user environment with no more than 10 user accessing the database at any given time. The host server is supporting approximately 4 other active databases. In general, there are approximately 60 active connections on the server. The incident we are trying to resolve has...
0
9886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5719
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.