Click here to Skip to main content
Licence CPOL
First Posted 1 Apr 2009
Views 6,861
Downloads 503
Bookmarked 11 times

SQL Database Restore

By | 1 Apr 2009 | Article
T-SQL string maker for backup with a MEDIAPASSWORD database.
 
Part of The SQL Zone sponsored by
See Also

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)

About the Author

Ahmet Göktaş

Software Developer
Istanbul Bilgi University
Turkey Turkey

Member

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralYou can do better PinmemberDonsw16:03 10 May '09  

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.

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