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. Database & SysAdmin
  3. Database
  4. Take a databse back up with LINQ ?

Take a databse back up with LINQ ?

Scheduled Pinned Locked Moved Database
csharpdatabaselinqtutorialquestion
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.
  • M Offline
    M Offline
    Mohammad Dayyan
    wrote on last edited by
    #1

    Hi guys. I'm using LINQ to modify a database. I want to take a back up from the database. Could you please guide me , how I can do it with LINQ ?

    N 1 Reply Last reply
    0
    • M Mohammad Dayyan

      Hi guys. I'm using LINQ to modify a database. I want to take a back up from the database. Could you please guide me , how I can do it with LINQ ?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You don't need Linq to backup a database. What is it that you want to accomplish?


      only two letters away from being an asset

      M 1 Reply Last reply
      0
      • N Not Active

        You don't need Linq to backup a database. What is it that you want to accomplish?


        only two letters away from being an asset

        M Offline
        M Offline
        Mohammad Dayyan
        wrote on last edited by
        #3

        I've created a SQL database beside my exe file, I'm trying to take backup from it through my application. At first , I've used File.Copy, but I receive this Exception cannot access because it is being used by another process Could you guide me, how I can do it ?

        N A 2 Replies Last reply
        0
        • M Mohammad Dayyan

          I've created a SQL database beside my exe file, I'm trying to take backup from it through my application. At first , I've used File.Copy, but I receive this Exception cannot access because it is being used by another process Could you guide me, how I can do it ?

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Mohammad Dayyan wrote:

          cannot access because it is being used by another process

          Perhaps your application? If the app uses a mdf file as a resource then it is possibly loading the file at start up. That should give you a start of where to look.


          only two letters away from being an asset

          1 Reply Last reply
          0
          • M Mohammad Dayyan

            I've created a SQL database beside my exe file, I'm trying to take backup from it through my application. At first , I've used File.Copy, but I receive this Exception cannot access because it is being used by another process Could you guide me, how I can do it ?

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            Run normal backup code from your application, rather than to use File.Copy. File.Copy needs the mdf files to be detached from your server instance which is not good technique.

            BACKUP DATABASE [DbName] TO DISK = N'C:\dbName.bak' WITH NOFORMAT, NOINIT, NAME = N'DbName-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10

            Just change the dbName, disk location for your backup and Name of the Backup file and run this using command.ExecuteNonQuery(). And believe me... you dont require LINQ for doing this . :-D :-D :-D

            Abhishek Sur


            My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

            **Don't forget to click "Good Answer" if you like to.

            M 1 Reply Last reply
            0
            • A Abhishek Sur

              Run normal backup code from your application, rather than to use File.Copy. File.Copy needs the mdf files to be detached from your server instance which is not good technique.

              BACKUP DATABASE [DbName] TO DISK = N'C:\dbName.bak' WITH NOFORMAT, NOINIT, NAME = N'DbName-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10

              Just change the dbName, disk location for your backup and Name of the Backup file and run this using command.ExecuteNonQuery(). And believe me... you dont require LINQ for doing this . :-D :-D :-D

              Abhishek Sur


              My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

              **Don't forget to click "Good Answer" if you like to.

              M Offline
              M Offline
              Mohammad Dayyan
              wrote on last edited by
              #6

              Thanks Abhishek Sur. I'm using LINQ, so I've used the following code :

              public static void GetBackUp()
              {
              if (!Directory.Exists(StaticVariables.BackUPFolder))
              Directory.CreateDirectory(StaticVariables.BackUPFolder);

              using (RezaRestaurant.SQL.DataClasses1DataContext dbc = new RezaRestaurant.SQL.DataClasses1DataContext())
              {
                  dbc.ExecuteCommand(@"BACKUP DATABASE " + dbc.Mapping.DatabaseName + " TO DISK='c:\\aaa.bak'");//Exception
              }
              

              }

              and this Exception has occurred : http://www.codeguru.com/forum/attachment.php?attachmentid=25454&d=1253973435[^]

              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