Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Is there a try/finally construct in sqlcmd with -b option, guaranteed to execute the finally block?

Is there a try/finally construct in sqlcmd with -b option, guaranteed to execute the finally block?

Scheduled Pinned Locked Moved Database
toolsquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    muhalet
    wrote on last edited by
    #1

    Can I use something like try/finally construction for guaranteed run script with -b option in sqlcmd? The task is: turn on single user mode run some scripts that may be errors guaranteed turn off single user mode

    L 1 Reply Last reply
    0
    • M muhalet

      Can I use something like try/finally construction for guaranteed run script with -b option in sqlcmd? The task is: turn on single user mode run some scripts that may be errors guaranteed turn off single user mode

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes, even Sql has the famous try..catch[^] block. Your "finally" would be included at the end of the "try" part.

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      J 1 Reply Last reply
      0
      • L Lost User

        Yes, even Sql has the famous try..catch[^] block. Your "finally" would be included at the end of the "try" part.

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Eddy Vluggen wrote:

        Your "finally" would be included at the end of the "try" part.

        Whaaaa....? No. Shirley that wont work like a finally block.

        L 1 Reply Last reply
        0
        • J J4amieC

          Eddy Vluggen wrote:

          Your "finally" would be included at the end of the "try" part.

          Whaaaa....? No. Shirley that wont work like a finally block.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Not guaranteed to execute indeed. Would it help to nest to try's, and check whether an error occured?

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          J 1 Reply Last reply
          0
          • L Lost User

            Not guaranteed to execute indeed. Would it help to nest to try's, and check whether an error occured?

            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            Eddy Vluggen wrote:

            Not guaranteed to execute indeed

            Well thats kinda the point of a finally block.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups