How to handle an error in TSQL and take control of the stored procedure

robert54

New member
Joined
Sep 10, 2020
Messages
1
Programming Experience
1-3
I never have learned error trapping in T-SQL. Darn. Sometimes curl.xget in

VB.NET:
SELECT @JSON = curl.xget(null, ''+@GETSTRING+'')

INSERT INTO [pcrd].[stg1_fredSeries]
           ([SeriesCode]
           ,[realStartTime]
           ,[realEndTime]
           ,[observationDate]
           ,[observationValue]
           ,[etl_dateUpdate]
           ,[ETL_UserUpdate]
           ,fk_series_id
           ,api_url)
    SELECT
        @SERIES_CODE AS SeriesID,
        *,
        GETDATE() AS etl_dateUpdate,
        'sp_get_fredSeriesPCTpe4' AS etl_userUpdate,
        @api_type,
        @GETSTRING
    FROM
        OPENJSON(@JSON,'$.observations')


Throws an error:

VB.NET:
Msg 6522, Level 16, State 1, Procedure pcrd.sp_get_fredSeriesPCType4, Line 72 [Batch Start Line 20]
A .NET Framework error occurred during execution of user-defined routine or aggregate "XGET":
System.Net.WebException: The remote server returned an error: (400) Bad Request.
System.Net.WebException:
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at Curl.Get(SqlChars H, SqlChars url)


Is this just a matter or raising an error and looking for Msg 6522? This insert and the building of the @GETSTRING is in a cursor fetch. Can there be a BEGIN TRY in a cursor fetch? Assuming this is the way to go.
 
I want to make sure that I understand what question you're asking here. You want to know how to catch and handle that exception in your SQL code, right? This has nothing specifically to do with VB.NET.
 

Latest posts

Back
Top