Sp_executesql And Error Handling
May 22, 2007
Hi,
I need to capture the error code while using sp_executesql
insert into #temp1
exec @status=sp_executesql @actn_id1
This @actn_id1 contains the proc name and the parameters. The problem now is when I get an error it’s not captured in the @status column, it always 0 and also tried @@error and was also 0.
Server: Msg 55118, Level 16, State 1, Procedure S_START_LUW, Line 383
info_upd_id =530129179546!, is using current subj_id.
This is a user defined error captured using raiserror inside a sub proc.
Can I capture this error number in the status column?
Thanks in advance for the help
View 5 Replies
ADVERTISEMENT
Oct 30, 2000
I am using dynamica SQL in one of my stored procs That performs BULKINSERT
on few tables.
If there is a PK constraint violation, I wanted to write an error routine.
But once SP_EXECUTESQL gives an error, the stored proc just abends
not allowing me to ado anything else.
Can anyone help me with some information on how to perform error
handling when I am using Dynamic SQL?
I am also sending the the piece of code and the error message.
CODE: Assume that all variables are declared appropriately.
SET @string = 'BULK INSERT Tb_Manfg ' + char(13) +
'FROM '+ '''' + @path_tb_manfg + '''' + char(13) +
'WITH (FIELDTERMINATOR = ' + '''' + '|=|'+ '''' + ',' + char(13) +
'ROWTERMINATOR = ' + '''' + '
' + '''' + ')'
IF @error = 0
BEGIN
PRINT 'NOW Tb_Manfg GOING TO BE INSERTED.......'
EXEC SP_EXECUTESQL @string
/*
This is where the stored proce abends.
The subsequent code is not executed at all.
*/
PRINT 'ERROR IS.........'
PRINT @@ERROR
IF @@ERROR = 2627
BEGIN
PRINT 'AN ERROR OCCURED WHILE INSERTING INTO Tb_Cateory'
SET @error = @@ERROR
return
END
ELSE
BEGIN
SET @error = @@ERROR
END
ERROR MESSAGE:
Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK__TB_Manfg__1FCDBCEB'. Cannot insert duplicate key in object 'TB_Manfg'.
The statement has been terminated.
Thanks a lot.
Sush.
View 1 Replies
View Related
Apr 21, 2006
1) We are writing a custome Source component for Oracle with OCI calls, Could some one please let me know how to Enable Error Handling for the Same,
2) Is it possible to write Custome Error Handeling Component for SSIS? if yes could you please help me on how to write it.
Thanks in advance.
View 1 Replies
View Related
Jul 23, 2005
Gurus,Here is what I ma trying to do. I have numeric expression stored in atable column. for e.g. @a + @b + @c. I supply values to the variablesat run time and want them to be computed at run time as per theexpression in the column.the stored procedure works fine but it gives a silly error.Any help greatly appreciated. Below is the code.--drop procedure proc_bkrcreate procedure proc_bkr ASdeclare @expr nvarchar(2000)declare @sql nvarchar(2000)declare @temp_exp nvarchar(3000)declare @ans integerdeclare @QFAAPAC02_1 integerdeclare @QFAAPAC02_2 integerdeclare @QFAAPAC02_3 integerdeclare @QFAAPAC02_4 integer-- Assigning values to variables -- Startset @QFAAPAC02_1 = (Select QFAAPAC02_1 from fa_ap_stage where recordid= 3)set @QFAAPAC02_2 = (Select QFAAPAC02_2 from fa_ap_stage where recordid= 3)set @QFAAPAC02_3 = (Select QFAAPAC02_3 from fa_ap_stage where recordid= 3)set @QFAAPAC02_4 = (Select QFAAPAC02_4 from fa_ap_stage where recordid= 3)-- Assigning values to variables -- Endset @temp_exp = (select num from translation where processid = 'AP' andlabel = 'C1')-- This is how num looks: @QFAAPAC02_1 + @QFAAPAC02_2 + @QFAAPAC02_3 +@QFAAPAC02_4--select @expr = '@QFAAPAC02_1 + @QFAAPAC02_2 + @QFAAPAC02_3 +@QFAAPAC02_4'-- Above line works fine but below one does not. though both are same.select @expr = @temp_expselect @sql = 'select @ans = ' + @exprexec sp_executesql @sql, N'@QFAAPAC02_1 integer, @QFAAPAC02_2 integer,@QFAAPAC02_3 integer, @QFAAPAC02_4 integer, @ans integer OUTPUT',@QFAAPAC02_1,@QFAAPAC02_2,@QFAAPAC02_3,@QFAAPAC02_ 4,@ans OUTPUTset @cc = @ansError Message: Server: Msg 137, Level 15, State 2, Line 1[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare thevariable '@QFAAPAC02_'.Thanks in Advance!Bkr
View 1 Replies
View Related
Jun 13, 2005
Hey all,
Having some trouble with a Database email system I created. The system consists of two tables, DATA_ELEMENT and EMAIL_MESSAGE. So the email message body and recipient fields may contain substitution macros such as {![CUST_EMAIL]!}. The CUST_EMAIL data element row then stores the SELECT, FROM and WHERE clauses separately. There is a stored proc to search the message body and recipients for these substitution macros and replace them with the appropriate values from the DB.
The system is working well except I have one particular substitution macro called VENUE_NAME_BY_PPPID which is causing a problem.
Quote: Server: Msg 207, Level 16, State 3, Line 3
Invalid column name 'PARTNER_PRODUCT_PRIZE_ID'.
And here's the query which is creates this error (without the escaped single quotes):
Code:
SELECT P.PARTNER_NAME + ISNULL(' - ' + PS.SITE_NAME, '')
FROM PARTNER_PRODUCT_PRIZE PPP
JOIN PARTNER_PRIZE PP ON PP.PARTNER_PRIZE_ID = PPP.PARTNER_PRIZE_ID
JOIN PARTNER P ON P.PARTNER_ID = PP.PARTNER_ID
LEFT JOIN PARTNER_SITE PS ON PS.PARTNER_ID = PP.PARTNER_ID
AND PS.PARTNER_SITE_ID = PP.PARTNER_SITE_ID
WHERE PPP.PARTNER_PRODUCT_PRIZE_ID = '19'
And just after this print statement, the query is executed with sp_executesql()
Any advice is greatly appreciated as this query runs fine when I execute from the query window. However, if I escape all the necessary quotes, I can't get it to run when I put the string inside of sp_executesql().
--Travis
View 1 Replies
View Related
Jul 20, 2006
Hi
I've got an SSIS package, I'm in a Data Flow step that has a OLE DB Command Data Flow Transformation.
The SQLCommand in the OLD DB Command is:
______________________
UPDATE Employment_Episode_Dim
SET Commence_Serv_Date = ?
WHERE AGS_Number = ?
______________________
The package will run through successfully, but I don't see any updates
in Employment_Episode_Dim. I ran a trace, and this is a sample of the
SQL that is being executed:
______________________
exec sp_executesql N'UPDATE EMPLOYMENT_EPISODE_DIM
SET COMMENCE_SERV_DATE = @P1
WHERE (AGS_NUMBER = @P2)',N'@P1 datetime,@P2 int',''2005-01-27
00:00:00:000'',78577229
______________________
If I take that SQL and execute it in a query window, it fails due to
two single quotation marks placed around the date parameter being used
as @P1.
Why does SQL/SSIS put two singles around the date? It's outside of the
string to be executed, so it doesn't seem to need to have the double.
Can anyone please help?
Thanks
Earth
View 2 Replies
View Related
Aug 22, 2007
Example code:
declare @somesql nvarchar(20)
execute sp_executesql @somesql, N'@lnCurrRow int', @lnCurrRow = 1
PRINT @@ERROR
@@Error returns 0, which is seems incorrect since @somesql is null. If you substitute @somesql for the constant NULL then an error is fired. The above also executes successfully with @@error = 0 if you set @somesql = '' (empty string).
EXEC behaves the same way.
It makes sense that executing an empty string should be fine, but NULL? Is there a SET option available that will cause an error to be raised if sp_executesql attempts to execute a nvarchar variable that's set to NULL?
Thanks.
View 4 Replies
View Related
Jul 23, 2005
This is a odd problem where a bad plan was chosen again and again, butthen not.Using the profiler, I identified an application-issued statement thatperformed poorly. It took this form:exec sp_executesql N'SELECT col1, col2 FROM t1 WHERE (t2= @Parm1)',N'@Parm1 int', @Parm1 = 8609t2 is a foreign key column, and is indexed.I took the statement into query analyzer and executed it there. Thequery plan showed that it was doing a scan of the primary key index,which is clustered. That's a bad choice.I then fiddled with it to see what would result in a good plan.1) I changed it to hard code the query value (but with the parmdefinition still in place. )It performed well, using the correct index.Here's how it looked.exec sp_executesql N'SELECT cbord.cbo1013p_AZItemElement.AZEl_Intid AS[Oid], cbord.cbo1013p_AZItemElement.incomplete_flag AS [IsIncomplete],cbord.cbo1013p_AZItemElement.traceflag AS [IsTraceAmount],cbord.cbo1013p_AZItemElement.standardqty AS [StandardAmount],cbord.cbo1013p_AZItemElement.Uitem_intid AS [NutritionItemOid],cbord.cbo1013p_AZItemElement.AZeldef_intid AS [AnalysisElementOid] FROMcbord.cbo1013p_AZItemElement WHERE (Uitem_intid= 8609)', N'@Parm1 int',@Parm1 = 8609After doing this, re-executing the original form still gave badresults.2) I restored the use of the parm, but removed the 'exec' from thestart.It performed well.After that (surprise!) it also performed well in the original form.What's going on here?
View 3 Replies
View Related
Feb 13, 2008
Hi,
Our report is working fine with data loaded from a stored procedure (#1) that contains a fairly simple Select statement. We need the same report to work with a dataset loaded from a stored procedure (#2) that uses 'Exec sp_executesql @queryString'. Unfortunately, attempts to call the latter cause an error in the report. From everything that I've read, there should be no difference between datasets created using either method. Any ideas what could be getting in the way of the latter?
I have doublechecked that the dynamic query is returning a valid dataset and that all the columns are in the same format as sp #1. The designer shows the dataset and the report with the data loaded, but the live system produces an error.
Any help is much appreciated.
Debbie
View 4 Replies
View Related
Jul 20, 2005
Hi All,I want to catch the next MSSQL error in my SQL code with following continuecalculationsServer: Msg 17, Level 16, State 1, Line 1SQL Server does not exist or access denied.If REMOTE_SERVER_1 is inaccessible (as in (a) below) the executing of SQLwill not continue with (b) - I need the code in (b) to run despite whetherthe previous exec was successful or not - Any ideas?begin transaction(a) exec REMOTE_SERVER_1...bankinsert '1' , '1' , 1 , 0 , 0(b) print @@errorcommit transactionwhere REMOTE_SERVER_1 is link to server created byEXEC sp_addlinkedserver @server = 'REMOTE_SERVER_1', @srvproduct = '',@provider = 'SQLOLEDB', @datasrc = 'MYCOMP1', @catalog = 'mirror2'EXEC sp_addlinkedsrvlogin @rmtsrvname = 'REMOTE_SERVER_1', .....Exec sp_serveroption 'REMOTE_SERVER_1', 'data access', 'true'Exec sp_serveroption 'REMOTE_SERVER_1', 'rpc', 'true'Exec sp_serveroption 'REMOTE_SERVER_1', 'rpc out', 'true'Exec sp_serveroption 'REMOTE_SERVER_1', 'collation compatible', 'true'Any help will be greatly appreciated
View 1 Replies
View Related
Jul 20, 2005
CREATE PROCEDURE dbo.Synchronization_GetNewRecords(@item varchar(50),@last datetime)ASSET NOCOUNT ONDECLARE @sql nvarchar(4000)SET @sql = 'SELECT * FROM ' + @item + ' WHERE LastUpdated >' + @lastEXEC sp_executesql @sql, N'@Type varchar(50), @Last datetime', @item, @lastThis is my SP. Very simple. But it is throwing the error in the subject line.Any help would be greatly appreciated.
View 1 Replies
View Related
Oct 13, 2006
Hi,
I am havin problems with the following giving a message
Msg 8114, Level 16, State 4, Line 0
Error converting data type varchar to datetime.
exec sp_executesql
@stmt=N'UPDATE CUSTOMER
SET [REQUEST] = @19, [DISC_EXPRY] = @28, [GROUP1] = @29, [GROUP2] = @31, [PR_LEVEL] = @48, [MOD_DATE] = @55, [MEM_CODE] = @63, [MEM_DATE] = @64, [HO_MOD] = @66, [LASTUPDATE] = @78
WHERE [ID] = @Old_1'
, @params=N'@19 nvarchar(4),@28 DateTime,@29 nvarchar(5),@31 nvarchar(5),@48 nvarchar(1),@55 DateTime,@63 nvarchar(7),@64 DateTime,@66 Integer,@78 Float,@Old_1 Integer',
@19= 'NRMA',@28= '1752-09-14',@29= 'ALBUM',@31= 'FRAME',@48= 'A',@55= '2006-10-10',@63= '1003.50',@64= '2006-10-10',@66= 3,@78= 39000.190633,@Old_1= 454636
however, as soon as I remove the datetime fields it works
exec sp_executesql
@stmt=N'UPDATE CUSTOMER
SET [REQUEST] = @19, [GROUP1] = @29, [GROUP2] = @31, [PR_LEVEL] = @48, [MEM_CODE] = @63, [HO_MOD] = @66, [LASTUPDATE] = @78
WHERE [ID] = @Old_1'
, @params=N'@19 nvarchar(4),@29 nvarchar(5),@31 nvarchar(5),@48 nvarchar(1),@63 nvarchar(7),@66 Integer,@78 Float,@Old_1 Integer',
@19= 'NRMA',@29= 'ALBUM',@31= 'FRAME',@48= 'A',@63= '1003.50',@66= 3,@78= 39000.190633,@Old_1= 454636
what am I doing wrong with the datetime parameters?
Grimhael
View 4 Replies
View Related
Nov 1, 1999
Hello,
I would like to supress an Informational error that SQL is returning when I run a stored proc that I created. The error message returned is:
Warning: Null value eliminated from aggregate.
The values returned from the stored proc are the results from a 'select * from #tmp_tbl". Before returning the values, I simply create the temp table, populate it and then run the select statement. Prior to getting my results, I get the error message. Can I suppress it and how?
Thank you.
View 1 Replies
View Related
Apr 16, 2008
Hi there,
Can anyone help me in catching @@error value.
I have a stored procedure which return @@error value, I need to read that in my dataaccesslayer and act according to it.
how do I catch the return value from stored procedure in my dataaccesslayer.
if I am not wrong @@error return a bool value
Thanks in advance.
View 1 Replies
View Related
May 1, 2008
dear friends i am writng a store procedure to insert into a two table .table 1 data inserted but when i inserting into a table2 it have some error at that time table 1 data also want to delete.give suggestions
View 3 Replies
View Related
Mar 14, 2000
I am writing a stored procedure that loads transaction logs to a database and I am having trouble trapping meaningful error messages. When ever the load fails, it gives me two error messages, the first one is meaningful and the second one just states that the load ended abnormally. Unforunately, when I capture the error using @@error after the load statement, it is the second error message that I am getting.
Is there anyway to trap the first error message as well?
Thanks
Angela
View 1 Replies
View Related
Jan 21, 1999
I currently have defined a source server, a transformation, and a destination server using DTS. How and where do I create an error routine that would capture any and all errors that would occur. This would include connection error, transformation errors etc. I know the errors can be written out to a text file but I would like them written to a table on my destination server.
The DTS package will be called from an external program using the xp_cmdshell extended stored procedure. We are using it this way as a flag so if one transformation fails it will return a 1. If all are successful it will return a O. These will be our flags to check the errors table in the destination server.
Could someone tell me where this code is to go and what the code will look like. Samples would be the most help.
Thanks
Tom
View 1 Replies
View Related
May 21, 2004
is there any way to do sometype of Error handling with in a Stored Proc? Example, If I have a deadlock, can I trap that error and execute other sql code or will always simply kill the stored proc?
View 1 Replies
View Related
Dec 12, 2006
I have a composite unique key on the audit_hub table that includes TimeStamp, UID, Type, Mailbox all as part of the unique key.
I’m trying to do inserts, and know that in some cases I will violate unique index.
I’m using stored procedure, and want to handle the error gracefully there – just move on.
Reading from text-based log files via .vbs and get back the nasty popup window.
Looks like I have it right but obviously I don’t considering how it’s (not) working.
I thought error handling would be the simplest way to avoid dupe records. Might be necessary to run the same log in more than once, and only want to add the new records since the last insert session.
Here’s what I have. It obviously simply halts and complains immediately after the insert attempt.
ALTER procedure eml_HubInsert
@TimeStamp bigint
,@UID varchar(255)
,@Type varchar(255)
,@MailBox varchar(255)
,@ServerID varchar(50)
as
insert into audit_hub (TimeStamp,UID,Type,Mailbox,ServerID)
values (@TimeStamp,@UID,@Type,@MailBox,@ServerID)
if @@ERROR = 2601
begin
return 0
end
View 2 Replies
View Related
Jul 25, 1998
Hallo... and sorry about my english
1 question:
What Error-Handling msut i mplement in a trigger, who is updating permanently two tables
in a database (with the follow commands: insert, delete and update) ???
thank you !
View 1 Replies
View Related
Dec 5, 2005
I have some stored procedures that insert information from a third party plugin that hooks into our database (so I can't do any client side validiation). The problem I am encountering is that some of the fields I use need to be in DateTime format. In order for SQL SERVER 2000 to be able to insert this field, the Date has to be in the correct syntax or an error is thrown.
Is there any way to do something like this in SQL SERVER 2000
Code:
DELCARE @SomeDate DateTime
Try
Set @SomeDate = CONVERT(DateTime, Parameter1, 101)
Catch
return custom error describing what field is formatted
wrong and exit stored procedure
END
View 3 Replies
View Related
Mar 3, 2005
I am running some bcp copies through a Sql job. I am copying 35 tables in individual steps. However, sometimes the bcp step fails to copy the data, and I want the step to fail if the data is not copied properly. Is that possible? If so, how? Any help is greatly appreciated.
View 2 Replies
View Related
Mar 8, 2005
I have this stored procedure that I need to add error handling to. How would I do that??
REATE PROCEDURE November2000
AS
SELECT TM#, LASTNAME, FIRSTNAME, FINALSUITDONE
FROM dbo.EmployeeGamingLicense
WHERE (FINALSUITDONE BETWEEN CONVERT(DATETIME,
'2000-11-01 00:00:00', 102) AND CONVERT(DATETIME,
'2000-11-30 00:00:00', 102))
GO
View 2 Replies
View Related
Feb 2, 2004
ppl,
i wrote this sql, seems v.straightforward to me.
It works first time round, sets the foreigh key, but second time round should error out to the handler - but it just reports the errors to the message out and dosn't seem to fire the errhandler.
Its gotta be a simple mistake - perhaps you could show me.
DECLARE @ErrorMsg int
BEGIN TRANSACTION
ALTER TABLE TPH_GlobalProductHierarchy
ADD CONSTRAINT SalesSubGrp_fk FOREIGN KEY (SalesSubGroupingID)
REFERENCES TPH_SalesSubGrouping (ID)
SET @ErrorMsg =@@ERROR
IF @ErrorMsg <>0 GOTO ErrorHandler
PRINT 'Success'
COMMIT TRANSACTION
ErrorHandler:
IF @ErrorMsg <> 0
BEGIN
PRINT 'Rollback'
ROLLBACK TRANSACTION
END
View 1 Replies
View Related
Apr 20, 2004
How can i use the system error messages. With RAISERROR
View 1 Replies
View Related
Jun 4, 2008
Can i any one help regd error handling while executing stored procedure.
Sample Sequence of execution :
CREATE procedure RBI_Control_sp
as
begin
set nocount on
begin try
BEGIN TRANSACTION
--Truncating the Table in ramcovm392(fin_ods)
exec fin_ods..trun_sp
--Data Transfer From the Live Server to Dw-Server
exec fin_ods..RBI_Data_Transfer_sp
insert into fin_wh..Status_report([object_name],row,[date])
select 'Data Tranfer','SUCCESS',getdate()
COMMIT TRANSACTION
end try
begin catch
<b> [i need to insert the type of error in status report table]</b>
rollback transaction
insert into fin_wh..Status_report([object_name],row,[date])
select 'Data Tranfer','FAILURE',getdate()
end catch
set nocount off
end
View 2 Replies
View Related
Mar 8, 2006
Hi all,
I am calling some stored procedures from ASP. These strored procedures have to deal with lots of deletes and updates. So i have thought of implementing transaction commits and rollbacks. But if a rollback occurs in these stored procedures, i want to get a value back to asp page, based on this value i will run the next stored procedure.
Can anybody give me some examples for doing this.
Somebody please help me with this!!!!!!!!!
Thanks a lot in advance,
Nitu
View 4 Replies
View Related
Jan 5, 2007
hello. below is a very simple SP i have coded to insert a user into my database. i have created a unique index for the username column on my database table. if the username already i want to convey this to my C# code which is attempting the insert. i am using a combination of TRY/CATCH, RAISERROR and @@ERROR here to achieve my aim. could somebody please look at my code and tell me if the error handling code is OK, or is it overly complicated?
AS
SET NOCOUNT ON
DECLARE @Error int;
BEGIN
BEGIN TRY
INSERT INTO Users(
Username,
Password,
FirstName,
Surname,
DateBirth,
Email,
Id_Country)
VALUES(
@Username,
@Password,
@FirstName,
@Surname,
@DateBirth,
@Email,
@Id_Country)
END TRY
BEGIN CATCH
SELECT @Error = @@ERROR;
IF @Error = 2601
RAISERROR('The username already exists.', 15, 1)
ELSE
RAISERROR('An unknown error occurred.', 15, 1)
RETURN @Error;
END CATCH
SELECT @Id_User = SCOPE_IDENTITY()
END
View 1 Replies
View Related
Jul 3, 2007
need example on how to add event handling condetion in a package using ssis.
my package runs in a loop. the loop creates a connection to diff servers and runs a dynamic query.
i want to add a feature which would let the loop run in the event of connection failure for one server.
thanks in adv
View 1 Replies
View Related
Sep 18, 2007
I have a stored procedure that inserts a new record into a table. The table it inserts into has a unique constraint that utilizes an identity column. Occassionally, this constraint gets violated due to the fact that the app running my stored procedure isn't the only application inserting into the table. Ideally, we would want to change the design to avoid this scenario but these are legacy applications that will eventually be sunsetted. My question is this; is there a way to handle the unique key constraint violation and prevent an exception being thrown in the app calling the stored proc? I know I can check for the error code and handle it within the stored proc but my app still gets an exception caught by the calling method. Can I prevent this from happening? I want for the insert to attempt again and if successful continue processing and not produce the exception. Any help would be greatly appreciated.
View 6 Replies
View Related
Sep 20, 2007
hi
in analysis services when i proccess a cube i got an error that
data from the fact table isnt exists in the dimenstion table
for example fact table sales has column suplier that one of its row
has data that doesnt match with the dimension table
how can i handle this error ?
can i insert instead someyhing else so that the proccess can continue and not failed ?
Thanks
Eyal
View 1 Replies
View Related
Sep 21, 2007
Hi,
I'm trying to decide on the best method for dealing with errors in a DTS package. It is sufficient to retrieve Step failure information after package execution but I have tried both methods. Specifically, these methods are detailed in http://support.microsoft.com/kb/240221. Another article - http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 - details the need to establish a single event sink to avoid "unexpected behaviour". I have used the code as described but noticed very little difference between post execution checking using GetExecutionErrorInfo and the PackageEventSink Interface. Using the Event Sink does retrieve one extra type of error, ie.
"Error at Destination for Row number 2. Errors encountered so far in this task: 1". This error will always give the row number as the last row in the file, in this case an excel file source. This is not really useful, but I don't want to detach the Event Sink because of the possibility of "unexpected behaviour". Could somebody advise? First is it possible to retrieve the line number, and secondly can anyone detail what an example of this unexpected behaviour might be? Finally, is there a way to retrieve a unique key constraint violation from a package if it occurs? It is only caught in the generalised way and produced as "Error at Destination...".
Thanks in advance
View 2 Replies
View Related
May 16, 2007
Hello,
I'm mainly a .net dev and now I want to create a TV function using the CLR inside SQL Server but I have some doubt about the error handling in the function itself and in t-sql.
I have a SP (that I suppose will have a BEGIN TRY ... END TRY BEGIN CATCH ...END CATCH) that call my TV function to get a table made of one row and 2 columns.
My TV function calls some private functions that uses .net classes so I want to handle the exception the potentially could happens.
But these expection shouldn't thrown the error to the caller SP because the SP must continue iven if there is a error but I would to inform somehow the SP that the fields in the table are null because something went wrong
What is the programming pattern to use?
If I write
<Microsoft.SqlServer.Server.SqlFunction(DataAccess:=DataAccessKind.None, FillRowMethodName:="FillDatesRow", isDeterministic:=True, Name:="GetDates", TableDefinition:="StartDate datetime,EndDate datetime")> _
Public Shared Function GetDates(ByVal UTCInputDate As Date) As IEnumerable
Dim StartDate As Date
Dim EndDate As Date
Dim rowArray As ArrayList = New ArrayList
Try
Dim GetDates (1) As Object
GetDates = Function1(UTCInputDate) 'Function that can cause exception directly or indirectly
GetDates (0) = StartDate
GetDates (0) = EndDate
rowArray.Add(GetDates)
Catch ex As Exception
????
End Try
Return rowArray
End Function
Private Shared Sub FillDatesRow(ByVal obj As Object, <Out()> ByRef StartDate As SqlDateTime, <Out()> ByRef EndDate As SqlDateTime)
Try
If obj IsNot Nothing Then
Dim row As Object() = CType(obj, Object())
If row(0) IsNot Nothing Then
StartDate = CType(row(0), DateTime)
Else
StartDate = SqlDateTime.Null
End If
If row(0) IsNot Nothing Then
EndDate = CType(row(1), DateTime)
Else
EndDate = SqlDateTime.Null
End If
Else
StartDate = SqlDateTime.Null
EndDate = SqlDateTime.Null
End If
Catch ex As Exception
Throw
End Try
End Sub
What I have to write in the GetDates' s catch block to avoid that the exception is thrown to the BEGIN CATCH END CATCH of the caller SP but inform anyway the caller??
Any tips and/or resources is welcome!
Thankx
Marina B
View 2 Replies
View Related