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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Restore .bak file through C# Coding in sql server

Restore .bak file through C# Coding in sql server

Scheduled Pinned Locked Moved C#
helpcsharpdatabasesql-serversysadmin
6 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.
  • N Offline
    N Offline
    NarendraSinghJTV
    wrote on last edited by
    #1

    hii all, I have managed to create a backup file (.bak) with the help of stored procrdure found on code project examples. Now i dont know how to restore this file with the existing one for the completion of restore. can any body help me out with this problem. Can we able to rstore it from c#.

    Regards Narendra Singh (Jindal Tech Ventures)

    RaviBeeR M 2 Replies Last reply
    0
    • N NarendraSinghJTV

      hii all, I have managed to create a backup file (.bak) with the help of stored procrdure found on code project examples. Now i dont know how to restore this file with the existing one for the completion of restore. can any body help me out with this problem. Can we able to rstore it from c#.

      Regards Narendra Singh (Jindal Tech Ventures)

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      See the SMO Restore[^] class. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • N NarendraSinghJTV

        hii all, I have managed to create a backup file (.bak) with the help of stored procrdure found on code project examples. Now i dont know how to restore this file with the existing one for the completion of restore. can any body help me out with this problem. Can we able to rstore it from c#.

        Regards Narendra Singh (Jindal Tech Ventures)

        M Offline
        M Offline
        Md Marufuzzaman
        wrote on last edited by
        #3

        Why you are not doing the restore process via a SQL stored procedure...?

        Thanks Md. Marufuzzaman


        Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

        N 1 Reply Last reply
        0
        • M Md Marufuzzaman

          Why you are not doing the restore process via a SQL stored procedure...?

          Thanks Md. Marufuzzaman


          Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

          N Offline
          N Offline
          NarendraSinghJTV
          wrote on last edited by
          #4

          yes i m trying to do it with the help of stored procedure but i m not getting the result i m using default restore command of sql server. do u have any idea or any example to give me a start.

          Regards Narendra Singh (Jindal Tech Ventures)

          M 1 Reply Last reply
          0
          • N NarendraSinghJTV

            yes i m trying to do it with the help of stored procedure but i m not getting the result i m using default restore command of sql server. do u have any idea or any example to give me a start.

            Regards Narendra Singh (Jindal Tech Ventures)

            M Offline
            M Offline
            Md Marufuzzaman
            wrote on last edited by
            #5

            The following stored procedure will restore the database. This is helpful when you need to restore the database from other applications: CREATE PROCEDURE [dbo].[sp_db_restore] @DBName varchar(60), @BackName varchar(120), @DataName varchar(60), @DataFileName varchar(120), @LogName varchar(60), @LogFileName varchar(120)    AS RESTORE DATABASE @DBName FROM    DISK = @BackName WITH MOVE @DataName TO    @DataFileName ,    MOVE @LogName TO @LogFileName, REPLACE GO Parameters    DBName - Database Name to be restored    BackName - Path & Name of the BackupFile    DataName - MDF File name    DataFileName - MDF File Path    LogName - LDF File Name    LogFileName - LDF File Path Replace: Will replace the Database if it exists.

            Thanks Md. Marufuzzaman


            Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

            N 1 Reply Last reply
            0
            • M Md Marufuzzaman

              The following stored procedure will restore the database. This is helpful when you need to restore the database from other applications: CREATE PROCEDURE [dbo].[sp_db_restore] @DBName varchar(60), @BackName varchar(120), @DataName varchar(60), @DataFileName varchar(120), @LogName varchar(60), @LogFileName varchar(120)    AS RESTORE DATABASE @DBName FROM    DISK = @BackName WITH MOVE @DataName TO    @DataFileName ,    MOVE @LogName TO @LogFileName, REPLACE GO Parameters    DBName - Database Name to be restored    BackName - Path & Name of the BackupFile    DataName - MDF File name    DataFileName - MDF File Path    LogName - LDF File Name    LogFileName - LDF File Path Replace: Will replace the Database if it exists.

              Thanks Md. Marufuzzaman


              Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

              N Offline
              N Offline
              NarendraSinghJTV
              wrote on last edited by
              #6

              thanks for ur reply i tried ur stored procedure but it gives the following error any idea how can i remove it "RESTORE cannot process database 'databasename' because it is in use by this session. It is recommended that the master database be used when performing this operation. RESTORE DATABASE is terminating abnormally."

              Regards Narendra Singh (Jindal Tech Ventures)

              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