Click here to Skip to main content
15,885,032 members
Articles / Programming Languages / C#

Genesis Hybrid Smart Client Framework part III

Rate me:
Please Sign up or sign in to vote.
4.29/5 (10 votes)
19 Jun 2009Ms-PL10 min read 34K   7  
This is part III of a VII part series. This article covers the back-end of the Genesis Smart Client Framework including the database design.
#region Copyright Clause
/*
 * Blue Marble Genesis Smart Client Framework
 * 
 * Copyright � 2009 Blue Marble. All rights reserved.
 * 
 * This code is protected from any unauthorized duplication or viewing under
 * international copyright laws. Unauthorized access to this code is prosecutable
 * under the full extent of the law.
 */
#endregion

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class deployment_database_backup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["DatabaseName"] == null)
        {
            Response.Write("Database name parameter not supplied!<br/>");

            Response.Flush();

            return;
        }

        if (Request.QueryString["ConnectionStringKey"] == null)
        {
            Response.Write("Database connection parameter not supplied!<br/>");

            Response.Flush();

            return;
        }

        Response.Write("Starting backup<br/>");
        Response.Flush();

        string commandText = @"
BACKUP DATABASE 
	[<%DatabaseName%>] 

TO DISK = N'<%BackupPath%><%DatabaseName%>.BAK' 

WITH 
	NOFORMAT, 
	INIT,  
	NAME = N'<%DatabaseName%>-Genesis Generated-Full Database Backup', 
	SKIP, 
	NOREWIND, 
	NOUNLOAD,  
	STATS = 10
";

        string backupPath = System.Configuration.ConfigurationManager.AppSettings["BackupPath"];

        backupPath += System.DateTime.Today.Year.ToString() + System.DateTime.Today.Month.ToString() + System.DateTime.Today.Day.ToString() + "\\";
        backupPath += System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + "\\";

        if (!System.IO.Directory.Exists(backupPath))
        {
            System.IO.Directory.CreateDirectory(backupPath);
        }

        commandText = commandText.Replace("<%DatabaseName%>", Request.QueryString["DatabaseName"]);
        commandText = commandText.Replace("<%BackupPath%>", backupPath);

        System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[Request.QueryString["ConnectionStringKey"]].ConnectionString);

        System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(commandText, connection);

        connection.Open();

        command.ExecuteNonQuery();

        connection.Close();

        Response.Write("Complete</br>");
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
We Fix Code
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions