Showing posts with label transaction. Show all posts
Showing posts with label transaction. Show all posts

Thursday, March 22, 2012

Cursed Error Messages

Hi everyone,
How do I get the error message?
I have a very long sproc that needs to be done in one transaction. I
have an error happening somewhere in the middle, but with a low enough
severity it doesn't terminate the procedure. To make sure I don't
miss any errors, I am storing @.@.error after every statement:
If @.Error<=@.@.error Set @.Error=@.@.error
that way at the end I can say if @.error<>0 rollback trans.
How do I get the error message? I have the number, and what I get
from sysmessages has the wildcards in it %d and so on.
Also , I can't use Xact_Abort, the web user permissions don't allow
it.

Or better yet is there a better way to do this? Sql has
@.@.total_errors - since the server was started, how about since the
transaction or the sproc was started.
Thanks a ton
Pachydermitis[posted and mailed, please reply in news]

Pachydermitis (dedejavu@.hotmail.com) writes:
> How do I get the error message?
> I have a very long sproc that needs to be done in one transaction. I
> have an error happening somewhere in the middle, but with a low enough
> severity it doesn't terminate the procedure. To make sure I don't
> miss any errors, I am storing @.@.error after every statement:
> If @.Error<=@.@.error Set @.Error=@.@.error
> that way at the end I can say if @.error<>0 rollback trans.
> How do I get the error message? I have the number, and what I get
> from sysmessages has the wildcards in it %d and so on.
> Also , I can't use Xact_Abort, the web user permissions don't allow
> it.
> Or better yet is there a better way to do this? Sql has
> @.@.total_errors - since the server was started, how about since the
> transaction or the sproc was started.

There is no way to get the text of the error message in SQL. You must
catch it on client level.

If your code is as above, there is a serious problem in your error
handling. @.@.error is set after each statement, so you will always
set @.error to 0 above.

I have an article on my web site about error handling, that you may
find useful. http://www.sommarskog.se/error-handling-I.html.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Monday, March 19, 2012

Current activity shows lots of SPID with open transactions...yet DBCC open tran shows no a

Anyone know why this is?
SQL Server 2000 sp3a.
There are about 200 spids in the database that show an open
transaction in the current activity window.
Yet, when I run a dbcc opentran on the database, it says no active
transactions.
An open transaction is one that has not yet commited correct? So
shouldn't it show up in DBCC opentran?
Thanks for any input."Sanctus" <mchi55@.hotmail.com> wrote in message
news:1175796327.218453.112050@.p77g2000hsh.googlegroups.com...
> Anyone know why this is?
> SQL Server 2000 sp3a.
> There are about 200 spids in the database that show an open
> transaction in the current activity window.
> Yet, when I run a dbcc opentran on the database, it says no active
> transactions.
> An open transaction is one that has not yet commited correct? So
> shouldn't it show up in DBCC opentran?
How are you determining the 200 Spids have open transactions?
Note that you may have 200 CONNECTIONS, but they may not be doing anything,
or they're doing very short transactions so you never get a chance to see
them with DBCC OpenTran.
> Thanks for any input.
>
--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html