tips & tricks


Calendario
febbraio 2025
lmmgvsd
272829303112
3456789
10111213141516
17181920212223
242526272812
3456789

Gestione degli errori TRY CATCH

TRY CATCH

Ecco un modo per gestire gli errori in sql con il blocco TRY CACH:


BEGIN TRY

    -- Generate a divide-by-zero error.

    SELECT 1/0;

END TRY

BEGIN CATCH

    SELECT

        ERROR_NUMBER() AS ErrorNumber,

        ERROR_SEVERITY() AS ErrorSeverity,

        ERROR_STATE() AS ErrorState,

        ERROR_PROCEDURE() AS ErrorProcedure,

        ERROR_LINE() AS ErrorLine,

        ERROR_MESSAGE() AS ErrorMessage;

END CATCH;




dà come risultato:

8134    16      1       NULL    6       Errore di divisione per zero.


Categoria: SQLServer
giovedì, 14 ott 2010 Ore. 12.57
Archivio Posts
Anno 2020

Anno 2018

Anno 2015

Anno 2013

Anno 2011

Anno 2010

Anno 2009

Anno 2008
Statistiche
  • Views Home Page: 15.301
  • Views Posts: 58.596
  • Views Gallerie: 2.837
  • n° Posts: 117
  • n° Commenti: 1
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003