none
Executing sql backup file through C# RRS feed

  • Question

  • Hi friends,

     

    I need to restore a database as backup file in SQLExpress automatically through C#. I mean, when user requests my program for the first time, I will show him/her an aspx to have an ability to restore backup file that is provided with project. For instance, (s)he will see all dbs in server with a dropdownlist and choose one of them to restore backed up file. What should I use libraries to implement this functionality or is there any sample source code?

     

    Thanks

    Saturday, May 17, 2008 11:05 AM

All replies

  •  gavroche wrote:

    Hi friends,

     

    I need to restore a database as backup file in SQLExpress automatically through C#. I mean, when user requests my program for the first time, I will show him/her an aspx to have an ability to restore backup file that is provided with project. For instance, (s)he will see all dbs in server with a dropdownlist and choose one of them to restore backed up file. What should I use libraries to implement this functionality or is there any sample source code?

     

    Thanks

     

    You write a stored procedure in Sql Server which will be just 3 lines of code or a bit more, look up RESTORE database command and call this SP from C# as follows:

     

    using (SqlConnection conn_accAccounting = new SqlConnection ( Globals.connStrAnalytical ))

    {

    SqlCommand cmdm = new SqlCommand ( );

    conn_accAccounting.Open ( );

    cmdm.Connection = conn_accAccounting;

    cmdm.CommandType = CommandType.StoredProcedure;

    cmdm.CommandText = "backUpAnalytical";

    cmdm.Parameters.Clear ( );

    try

    {

    cmdm.ExecuteNonQuery ( );

    }

    catch

    {

    TSP.textToSpeech ( "Backup Device is disconnected" );

    return;

    }

    }

     

    This is actually for a Backup operation. Yours will be practically the same.

Saturday, May 17, 2008 12:48 PM