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. Restore database using t-sq

Restore database using t-sq

Scheduled Pinned Locked Moved Database
databasequestionhelp
5 Posts 5 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.
  • W Offline
    W Offline
    WDI
    wrote on last edited by
    #1

    hi i have developed some t-sql to backup/restore any database. while restoring a database, if any session or connection be active on it i can not restore database and recieve exception. How can i restore such databases? How can i kill all sessions from database to solve my problem?

    P S M 3 Replies Last reply
    0
    • W WDI

      hi i have developed some t-sql to backup/restore any database. while restoring a database, if any session or connection be active on it i can not restore database and recieve exception. How can i restore such databases? How can i kill all sessions from database to solve my problem?

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      WDI wrote:

      How can i kill all sessions from database to solve my problem?

      That would not be nice for your users. Imagine, you are working along and wham database session is killed and you lose work.

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer

      S 1 Reply Last reply
      0
      • P Paul Conrad

        WDI wrote:

        How can i kill all sessions from database to solve my problem?

        That would not be nice for your users. Imagine, you are working along and wham database session is killed and you lose work.

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer

        S Offline
        S Offline
        Stathread
        wrote on last edited by
        #3

        I second that, those type of tasks are usually scheduled for when people are not working.

        www.codewash.com

        1 Reply Last reply
        0
        • W WDI

          hi i have developed some t-sql to backup/restore any database. while restoring a database, if any session or connection be active on it i can not restore database and recieve exception. How can i restore such databases? How can i kill all sessions from database to solve my problem?

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          The only way I can think to end all the sessions would be by stopping the SQL service and then restarting it, your users might open their session again by the time you have started restoring though in which case it will still fail. You could just run the command "NET STOP MSSQLSERVER" and then "NET START MSSQLSERVER" within your application. There probably is a better way though but like the others said, it's probably not a good idea.

          There are 10 types of people in the world, those who understand binary and those who dont.

          1 Reply Last reply
          0
          • W WDI

            hi i have developed some t-sql to backup/restore any database. while restoring a database, if any session or connection be active on it i can not restore database and recieve exception. How can i restore such databases? How can i kill all sessions from database to solve my problem?

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            You can put the database into a mode where only a single connection is allowed at a time by using ALTER DATABASE _db_ SET SINGLE_USER. Use the WITH ROLLBACK option to tell SQL Server when to rollback/abort any other existing connections. The connection you run ALTER DATABASE from remains connected. You may also be able to restore the database if you take it OFFLINE.

            Stability. What an interesting concept. -- Chris Maunder

            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