Results 1 to 8 of 8

Thread: [RESOLVED] SQL Server Express Backup

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Resolved [RESOLVED] SQL Server Express Backup

    I am trying to create a Win Form that can create a DB backup with the click of a button. I am trying to allow the user to set the directory to where the ".bak" will go.

    Here is what I have:
    HTML Code:
    if (saveBackupDialog.ShowDialog() == DialogResult.OK)
                {
                    Backup bu = new Backup();
                    bu.Action = BackupActionType.Database;
                    bu.Database = "Test";  //database name
    
    
                    //BackupDeviceItem bdi = new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File);
    
                    BackupDeviceItem bdi = new BackupDeviceItem("Test.bak", DeviceType.File);
    
                    bu.Devices.Add(bdi);
    
                    try
                    {
                        Server server = new Server(); //server
                        bu.SqlBackup(server);
                    }
                    catch (Exception x)
                    {
                        MessageBox.Show(x.ToString());
                        Close();
    
                    }
                }
    If you look at the BackupDeviceItem, the commented outline is what I want to do. I want to store the backup to that location. But if I only use a filename it works (the uncommented line) and puts the file in "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup" .

    Basically instead of putting the file in C:\\Program Files... I want it to go where teh user selects from the savedialog. Any help is appreciated.

    Thanks

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: SQL Server Express Backup

    Any ideas from anyone, I would really like to be able to do this.

    Thanks

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: SQL Server Express Backup

    What actually happens if you try to use a full path? If it won't let you do it then it probably isn't supported.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SQL Server Express Backup

    Step through your code and look at what saveBackupDialog.FileName has as its value.

  5. #5
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: SQL Server Express Backup


  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: SQL Server Express Backup

    Savefilebackup has "C:\Documents and Settings\Mike\My Documents\Backup.bak" which is the correct path to where i want to run it.

    Is it possible to run a stored procedure in C#? I really dont understand them so I would like to do what I'm trying now.

    thanks

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: SQL Server Express Backup

    Quote Originally Posted by ekim12987
    Is it possible to run a stored procedure in C#? I really dont understand them so I would like to do what I'm trying now.
    Have a look here

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: SQL Server Express Backup

    Thanks, I got that to work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width