473,698 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a Transaction with a SqlDataSource

I have a problem on my SqlDataSource.
Once my SqlDataSource has Inserted, I need to run a stored procedure.
The return from this stored procedure determines if Icommit or rollback.

Here is my approach:

http://rafb.net/p/b53pmq89.html

When the ExecuteNonQuery is fired the following exception is thrown:

"Transactio n count after EXECUTE indicates that a COMMIT or ROLLBACK
TRANSACTION statement is missing. Previous count = 1, current count =
0."

Anyone know what the problem is, or is my approach wrong?

Steven


*** Sent via Developersdex http://www.developersdex.com ***
May 17 '07 #1
3 6689

"Steven Blair" <st**********@b tinternet.comwr ote in message
news:eN******** ******@TK2MSFTN GP05.phx.gbl...
>I have a problem on my SqlDataSource.
Once my SqlDataSource has Inserted, I need to run a stored procedure.
The return from this stored procedure determines if Icommit or rollback.

Here is my approach:

http://rafb.net/p/b53pmq89.html

When the ExecuteNonQuery is fired the following exception is thrown:

"Transactio n count after EXECUTE indicates that a COMMIT or ROLLBACK
TRANSACTION statement is missing. Previous count = 1, current count =
0."

Anyone know what the problem is, or is my approach wrong?
e.Command.Trans action.Commit() should be placed right after
e.Command.Execu teNonQuery(), because the execution of the StoreProcedure
returned good. It took the non-exception path, the transactions should be
committed. What are you wafting for?

The e.Command.Trans action.Rollback () should be placed in the scope of the
Catch, with a possible check to see if the connection is Open and close the
connection before you Throw (ex) to leave the routine.

The Finally should be checking for connection Open and Close the connection
if open.

Have you heard of the ADO.Net Using statement, which should not to be
confused with the Namespace Using statement, use Google and look it up.
..

May 17 '07 #2
Would the Using correct the problem (the exception I have)?

As for the structure of the code, in your example, how would you cater
for the stored procedure returning an invalid response (no exception
thrown but a report of failure?)
My appraoch caters for both exceptions and the stored proecedure
failing.

*** Sent via Developersdex http://www.developersdex.com ***
May 18 '07 #3

"Steven Blair" <st**********@b tinternet.comwr ote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...
Would the Using correct the problem (the exception I have)?
No, it's just a another way of opening a connection, which can be applied
down to the ADO.Reader level. The ADO.Net.Using also closes the things was
well. You should look up some examples using Google.
>
As for the structure of the code, in your example, how would you cater
for the stored procedure returning an invalid response (no exception
thrown but a report of failure?)
My appraoch caters for both exceptions and the stored proecedure
failing.
Well, I would set a Return Code on the Return statement of the Stored
Procedure.

If it returns zero, then do the commit, else Throw a New Exception, which
will make the logic go to the Catch.

That return of failure I would assume is something you're going to return
using the Return code yourself, because if there is a problem in the Stored
Procedure in executing, then an Exception is going to be thrown by SQL
Server.

I think your other problem the way you have it coded is the Finally is out
of the scope of the transaction, with the commit or rollback.

May 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6040
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is "LabLocation_ID". With an existing lab, they then need to add the members for that lab. So, what I am trying to do is the following. With the FormView of the Lab open, the user will click a button to open a FormView (InsertMode) and add a new...
0
2206
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase .NET 2.0 DataProvider (iAnywhere.Data.AsaClient.dll) into the GAC so it can be used in the ProviderName property of a SQLDataSource and loads properly at run time. The application I'm writing is a bit more complex than the example I'm about to...
3
2327
by: Jim Andersen | last post by:
Hi, I would appreciate if someone could explain this behaviour, and maybe offer a better solution. I have been working with the GridView control. And SqlDataSource. It works great if I do: <asp:SqlDataSource ConnectionString="yada yada yada" etc etc />. I can hook up a GridView to the sqldatasource and view/edit/add records.
3
5153
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and sqldatasource control. I know that while using sqldatasource control, there is no need of opening and closing a connection. Also there is no need to write connection string. When i am selecting table from sqldatasource and writing insert statement in C# code, its working fine. When I am...
5
7683
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason, the compiler believes an SQL db is being accessed ("An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does...
7
2881
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM", "OE_HDR"."SLS_MAN_NO", "OE_HDR"."SLS_MAN_INITIALS", "OE_HDR"."ORD_DAT", "OE_HDR"."SHIP_DAT" FROM "OE_HDR" WHERE ("OE_HDR"."ORD_NO"='174310') I also have DropDownList1 working properly. For the WHERE portion of
2
5509
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created programmatically. And I want to bind the selection of a TreeNode (which is a record) from the database) to a DetailsView which shows the datatable record for the selected TreeView node in the Details View. I am using IDE : Visual Web Developer 2005 Express; OS=...
1
1162
by: sweatha | last post by:
Hi I connected SQLDataSource in GridView by using coding <asp:GridView ID="Search_GridView" runat="server" Style="z-index: 100; left: 2px; position: absolute; top: 270px" AutoGenerateColumns="False" OnSelectedIndexChanged="Search_GridView_SelectedIndexChanged" CellPadding="20" Width="720px" AllowPaging="True" OnPageIndexChanging="Search_GridView_PageIndexChanging" DataSourceID="SqlDataSource1"> ...
6
1877
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as pressing a button or changing text in a textbox). It gets set up and on the user control on my web page I can see the event from intellisense. So it seems to be set up, but I am trying to get an easy example of how I would now use this event. ...
0
8598
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,...
1
8885
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
8855
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
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
4358
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
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
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.