Click here to Skip to main content
Click here to Skip to main content

SQL Database Restore

, 1 Apr 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

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)

Share

About the Author

Ahmet Göktaş
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 PinmemberDonsw10-May-09 17:03 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 1 Apr 2009
Article Copyright 2009 by Ahmet Göktaş
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid