Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2003, 05:46 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default what is the benefits for each approach

i am asking what is the benefits for each approach, and what is the best for each of:
first:
sending transaction as a text from Program Side and execute it on the sqlServer, for example


BEGIN TRANSACTION

'statment 1
if @@error<>0 RollBack TRANSACTION

'statment 2
if @@error<>0 RollBack TRANSACTION

COMMIT TRANSACTION


or second:

doing that with code using Connection object(I am using ADO.NET)
and checking exceptions to decide if rollback


 cn.BeginTransaction
try
 ' statment one
 ' statment two
 '......
 cn.commit

catch
 cn.RollBack
end try


Ahmed Ali
Software Developer
__________________
Ahmed Ali
Senior Software Developer
 
Old December 22nd, 2003, 12:10 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you know about potential errors within the SQL it would tend to reason that handling the transaction and possible rollback directly in SQL would be more efficient. I have heard however that the performance of ADO.net SqlClient transaction functionality is close to direct SQL.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 22nd, 2003, 06:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think the rule of thumb in scenario's like this is that you should let the database handle the transactions when all of them take place in a single database and database server (that is, you can easily put those statements in a Transaction inside a Stored Procedure).

You should use ADO / ADO.NET transactions when your statements are targeted at different databases and / or database servers or require multiple calls to the same datasource.

The first way will skip the creation of transaction objects on the "client" which will be a bit faster.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 22nd, 2003, 11:08 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

thx perter,Imar

but Imar
Quote:
quote:You should use ADO / ADO.NET transactions when your statements are targeted at different databases and / or database servers .
as you said you should use ado when dealing with multi database servers , i know that sqlServer can do remote transactions.


Quote:
quote:or require multiple calls to the same datasource.
And what is the difference if i do multible calls to the same datasource with the two approachs(why ado.net here).




Ahmed Ali
Software Developer
 
Old December 23rd, 2003, 04:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

SQL Server may be able to do remote transactions, but I was referring to a broader scenario, where you're trying to run a transaction on both Oracle and SQL Server for example.

Executing multiple calls requires you to use ADO.NET transactions, or some other transaction manager. Consider this:
Code:
// ADO.NET
// Execute First Stored Procedure
// Execute Second Stored Procedure


-- Stored Procedures
-- Procedure 1
-- Create Transaction
DELETE FROM SomeTable

-- Procedure 2
-- Create Transaction
UPDATE SomeOtherTable bla bla
In this example, .NET code calls two stored procedures. Each Stored Procedure uses a transaction to protect the integrity of the data the procedure is responsible for. But how do you synch the two calls? How do you roll back the first transaction when the second fails?

Because there is no connection between the two calls to the procedures, you'll need an ADO.NET transaction to run both procedures correctly and safely.

Does this help?

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 24th, 2003, 01:46 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

thx Imar but,
scenario you explain could be done using nested transactions.

Ahmed Ali
Software Developer
 
Old December 31st, 2003, 05:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, you asked what the benefits were. Not what the only possible solution is.

There are multiple ways to do the same thing. You can create Transactions in SQL Server, in .NET, or you can even use the Distributed Transactions Coordinator. It's up to you to decide what fits in where.

From what I know about Nested Transactions, I think they are executed by the client (well, at least in the scenario we're describing here, inside a Sproc is different of course). In that respect, I don't think there is much of a difference between Nested Transactions and using a client side transaction, but I could be totally wrong.

Sorry for not responding earlier. Overlooked this message.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Lotus approach and .NET joeri VS.NET 2002/2003 3 August 10th, 2007 08:47 AM
Need help with approach rickyc1 Classic ASP Databases 4 July 14th, 2005 10:26 AM
Datasets - what is the best approach? Dave Stumbles VB Databases Basics 0 January 12th, 2005 05:21 PM
what is the common approach for it? thanks Robin1 Classic ASP Databases 6 September 11th, 2004 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.