Are these both same? Begin Tran & Begin Try

  • Are all errors logged on try catch ? I ran the code and manually killed the connection, for some reason didn't get logged. It did do the rollback though. I would like to capture errors in all scenario's also like when server is crashed.

  • curious_sqldba - Thursday, August 3, 2017 11:24 PM

    I ran the code and manually killed the connection, for some reason didn't get logged. It did do the rollback though. I would like to capture errors in all scenario's also like when server is crashed.

    How would a disconnection be caught in the catch block? If the session no longer exists, the catch in that session cannot run. Same with a server crash. The catch can't run, because the server's not available to run it

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • But it should be able to rollback right? If the server crashes i am thinking once the server is back it should rollback all the uncommitted transactions. Really i am trying to avoid a situation where i have inserted but not deleted the data or vice versa.

    Appreciate your feedback.

  • curious_sqldba - Friday, August 4, 2017 8:21 AM

     If the server crashes i am thinking once the server is back it should rollback all the uncommitted transactions. .

    Um, you do know that's what SQL does automatically as part of its startup process?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Got it.

    Looks like my Try/Catch is not trapping all errors. For example if the table name is wrong it doesn't log.

  • Parse-time and binding errors occur before any portion of the code starts to execute, and hence can't be caught by try-catch.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 6 posts - 16 through 20 (of 20 total)

You must be logged in to reply to this topic. Login to reply