Sunday, March 11, 2012
errors in storedprocedures
http://weblogs.sqlteam.com/brettk/archive/2004/05/25/1378.aspx
Wednesday, March 7, 2012
Errorhandling in batches
Hi there,
I would like to know, if there is a way to handle errors in a batch without the batch being stopped? Take next example:
Two tabeles, SOURCE and DEST, both with columns ID as INT(primary key) and NAME as varchar(20).
When I do this: this statement will break with a duplicate key violation error when an existing
insert into DEST
select ID, Name
from SourceTable
This statement will break with a duplicate key violation error when an existing value is entered. Is there any way I can prevent this from happening? I am aware that with something like SELECT @.error = @.@.error and @.rowcount = @.@.rowcount I can find out what went wrong and locate the offending row. However, sofar I am not able to reset @.@.error to 0 again within the bacth.
Is this at all possible? I can make something like this with a CURSOR, but would like not to use this technique. Basically I want the offending records inserted into antother(error)table to deal with after the batch has completed.
TIA,
FreeHansje
First, select out the 'good' rows, and then the 'bad' rows.
INSERT INTO Dest
SELECT ID, Name
FROM SourceTable s
JOIN Dest d
ON s.ID <> d.ID
INSERT INTO DupIDs
SELECT ID, Name
FROM SourceTable s
JOIN Dest d
ON s.ID = d.ID
|||Tnx for responding, Arnie.
This sure is a very good solution. This is however just an example, other errors may occur. I'd have to think up all possible errors and check the data for specifically those. I was hoping for a general way of isolating those error-records in the statement itself. But more and more I believe that's not possible.
Tnx again,
Sunday, February 26, 2012
error_line() not accurate?
Hello,
I'm just trying out this new try-catch stuff in sql server 2005....
Using the example from the help, "Using TRY... CATCH in Transact-SQL" , it shows how things are done in the adventure works database.. loggin the error to the errorlog table and all that... looks great.. but I notice that when I implement this code in my project.. and tested by putting in a line that causes a divide by zero error... that the line number reported by error_line is acutally not the line at which the divide by zero code resides....
Any suggestions as to what would put the error_line out of whack? I have comments and some string literals in the code..would they be throwing it?
Thanks
Try posting a sample here that others can recreate. That way we can address the issue specifically.
error_line() not accurate?
Hello,
I'm just trying out this new try-catch stuff in sql server 2005....
Using the example from the help, "Using TRY... CATCH in Transact-SQL" , it shows how things are done in the adventure works database.. loggin the error to the errorlog table and all that... looks great.. but I notice that when I implement this code in my project.. and tested by putting in a line that causes a divide by zero error... that the line number reported by error_line is acutally not the line at which the divide by zero code resides....
Any suggestions as to what would put the error_line out of whack? I have comments and some string literals in the code..would they be throwing it?
Thanks
Try posting a sample here that others can recreate. That way we can address the issue specifically.
ERROR_BROKER_CONVERSATIONS: practical example?
Hello,
I read that is there is this Database setting for service broker: ERROR_BROKER_CONVERSATIONS
I have not understood the how to use this setting in real scenario.
Could somebody provide me some practical example?
White papers are also ok! :-)
Thank you
Marina B.
The primary reason this option was introduced is for the scenarios when two databases that have conversations with each other and one of them has an incident and data loss occurs (it has to be restored back in time). Since the conversations between the two databases are now out of sync, the one that was restored back in time should ERROR_BROKER_CONVERSATIONS in order to error all existing conversations before enabling the broker. The application should be prepared to deal with the Error message anyway, and this is a quick way to send an Error message on all conversations. After this, the broker in the database is enabled and keeps the old broker instance (aka. service_broker_guid, thus all routes to it are still valid).Friday, February 24, 2012
Error: The service queue "ClientQueue" is currently disabled.
Well I downloaded an example (HelloWorld) from www.SQLServiceBroker.com yesterday and it WAS working this morning, however; now I'm getting this error:
The service queue "ClientQueue" is currently disabled.
Which I found from looking at the Service Broker Statistics Report is true. There are 5 queues total and only the dbo.ClientQueue is disabled.
Questions:
1). How do I enable it?
2).What caused it to become disabled?
I tried running the following commands:
1). alter database [dbo].[ServiceQueue] set enable_broker
2). alter database [ServiceQueue] set enable_broker
within the Microsoft SQL Server Management Studio.
Thanks
God Bless...
doug
1) ALTER QUEUE [ClientQueue] WITH STATUS = ONSee http://msdn2.microsoft.com/en-us/library/ms189529.aspx
2) Most likely you rolled back 5 RECEIVEs in a row, activating poison message detection.
See http://msdn2.microsoft.com/en-us/library/ms166137(en-US,SQL.90).aspx
HTH,
~ Remus|||Thanks!
That Worked!
Doug