Link to home
Start Free TrialLog in
Avatar of jonatec
jonatecFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Controlling SQL Transactions with SQL Server 2000 and ADO.NET

Hi

I have to work on a system that has a SQL Server 2000 database. I am using C# and ADO.NET to access the database. I now have an update to do with 4 tables. Now with SQL Server 2008 I can use a try.. catch block and rollback any failed updates. But given the technology I'm using can someone suggest the most sensible way to begin/rollback/commit a transaction with SQL Server 2000 ?

Many thanks..
ASKER CERTIFIED SOLUTION
Avatar of chandrasekar1
chandrasekar1
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonatec

ASKER

Thanks for that.

Question I have is; will SQL Server 2000 control an error caused when a table or column has been accidentally renamed or a column deleted, or will it just crash out ?
It will give a severe error, not controlable just stops , rollback and gives error like 'unkown ...'  
From SQL2005 you have more control.  But 'accidentally' renamed or deleted column is something
it will crash, if you want to avoid this situation, before doing the DML operation, you can check in the “information_schema.columns” view and then you can proceed it.
The sql will crash, but the error returned is perfectly capturable in your C#-code to let it there have an elegant exit.
Avatar of jonatec

ASKER

Is it better to escalate the problem back to ADO.NET and create a rollback there ?
SOLUTION
Avatar of Henrik Staun Poulsen
Henrik Staun Poulsen
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonatec

ASKER

Thanks. Very useful.
you should not use Approach 2, as

SQL Server sets @@error to 0 if the statement was successful

Avatar of jonatec

ASKER

Agreed. I'll use approach 1.