1

while click the backup btn it opened a savefiledialog box but i couldnt find .bak extension at save as type code: private void backupdb_Load(object sender, EventArgs e)
{ label4.Visible = false;

        DataSet ds = SqlGetData.GetData1("select srvname  from sysservers  where srvproduct='SQL Server'");

        for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
        {
            cbserver.Items.Add(ds.Tables[0].Rows[0][m].ToString());
        }
    } 

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { cbdb.Items.Clear(); DataSet ds = SqlGetData.GetData1("select name from sysdatabases"); for (int m = 0; m < ds.Tables[0].Rows.Count; m++) { cbdb.Items.Add((ds.Tables[0].Rows[m][0].ToString()).ToString()); } }

    private void button1_Click(object sender, EventArgs e)
    {

        blank("backup");


    }

    public void blank(string str)
    {
        if (string.IsNullOrEmpty(cbserver.Text) | string.IsNullOrEmpty(cbdb.Text))
        {

            label4.Visible = true;
            MessageBox.Show("Server Name & Database can not be Blank");
            return;

        }
        else
        {
            if (str == "backup")
            {
                saveFileDialog1.FileName = cbdb.Text;
                saveFileDialog1.ShowDialog();
                string s = null;
                s = saveFileDialog1.FileName;
                saveFileDialog1.Filter = "All Files|*.bak";
                query("Backup database " + cbdb.Text + " to disk='" + s + "'");

                label4.Visible = true;
                label4.Text = "Database BackUp has been created successful";



            }
        }

1 Answer 1

0

Move the line to set the filter to be before the dialog is displayed

saveFileDialog1.Filter = "All Files|*.bak"
saveFileDialog1.ShowDialog();
4
  • I have done as you said. The file also saved in the particular section but I didn't get any .bak file in saved location. What could be the solution for this? Please help me out from this problem? Commented Sep 29, 2014 at 10:00
  • Sorry I thought your problem was why was there no "Save as" type listed for .bak listed in the dialog. Can you clarify the problem? You don't seem to have any code for actually saving/creating a file..
    – steve16351
    Commented Sep 29, 2014 at 10:04
  • I want to save the sql db backup file in the local drive. I got the message as well saying "Database successfully saved." But still I haven't get the file in my local drive. Commented Sep 29, 2014 at 10:08
  • 1
    I take it the Backup database query executes without error? Also if the db is on a different server, the path would have to be available on that server. For example, if you specify c:\backups as the path, it will save to that path, on the server, not where your app is running from.
    – steve16351
    Commented Sep 29, 2014 at 10:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.