Click here to Skip to main content
15,881,873 members
Articles / Desktop Programming / Windows Forms

SQL Database Restore

Rate me:
Please Sign up or sign in to vote.
3.33/5 (3 votes)
1 Apr 2009CPOL 21.6K   1.1K   12   1
T-SQL string maker for backup with a MEDIAPASSWORD database.

Introduction

This application is third party tool for creating T-SQL scripts for database restore operations.

You can restore a database from the SQL Server Management Studio GUI, but you cannot restore a protected backup file with MEDIAPASSWORD! In that case, you must write a SQL string, but that is very boring.

This tool gives you a chance to make a SQL string quickly, and you can make a differential restore string. This application stores your connection info in an XML file.

Using the code

This code shows you the backup file's appends:

C#
private void btnSelectDiffFile_Click(object sender, EventArgs e)
{
    try
    {
        isConnected();

        if (_isConnected & server != null & !string.IsNullOrEmpty(_remoteUser) 
                         & !string.IsNullOrEmpty(_remotePass))
        {
            string cUser = _remoteUser != null ? _remoteUser : string.Empty;
            string cPass = _remotePass != null ? _remotePass : string.Empty;

            FileSelectDialog fileselect = new FileSelectDialog();
            DialogResult result = fileselect.ShowDialog(server,cUser,cPass);
            if (result == DialogResult.OK)
            {                        

                string backtoLocalName = fileselect.Show();
                backtoLocalName = backtoLocalName.Replace("$", ":");
                backtoLocalName = backtoLocalName.Replace(_serverName != null ? 
                                  _serverName : string.Empty, string.Empty);
                backtoLocalName = backtoLocalName.Replace("\\\\\\", string.Empty);
                txtDiffFile.Text = backtoLocalName;
                
                Restore res = new Restore();
                res.Devices.AddDevice(backtoLocalName, DeviceType.File);

                DataTable dt = res.ReadBackupHeader( server );

                CreateTextBoxColumn( grdDiffBackups, "BackupName", "BackupName" );
                CreateTextBoxColumn( grdDiffBackups, "Position", "Position" );
                CreateTextBoxColumn( grdDiffBackups, "BackupStartDate", 
                                     "BackupStartDate" );
                grdDiffBackups.AutoGenerateColumns = false;
                
                bsDiff.DataSource = dt;
                
                grdDiffBackups.DataSource = bsDiff;
            }
        }
        else
        {
            MessageBox.Show("Username/Password is null or empty!");
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Istanbul Bilgi University
Turkey Turkey
- Software developer from İstanbul/Turkey
- Programmed with C#.NET, ASP.NET, ASP, PHP, T-SQL
- SQL Server Administration
- Experiencing about NHibernate

Comments and Discussions

 
GeneralYou can do better Pin
Donsw10-May-09 16:03
Donsw10-May-09 16:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.