Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to take database back up from asp.net.

i try BACKUP DATABASE [tablename] To DISK = [path]
using stored procedure and query text

exception shown - "Cannot perform a backup or restore operation within a transaction.BACKUP DATABASE is terminating abnormally"

Cant we take database back up from code behind in asp.net

Thankyou
Yesu
Posted

Refer following link


[This^]
 
Share this answer
 
Comments
Hiren solanki 20-Jan-11 7:16am    
Link is not working.
soni uma 20-Jan-11 7:27am    
May be my mistake in formatting

This is link
http://www.mssqltips.com/tip.asp?tip=1070
Take a look at this.
string ConnectionString="Place Your ConnectionString";
public static void GenerateBackup(string DBName,string Location)
        {
            if (ConnectionString.Length > 0)
            {
                System.Data.SqlClient.SqlConnection dbConn = null;
                try
                {
                   
                    string Query = "BACKUP DATABASE "+DBName+" TO DISK = '" + Location+ DateTime.Now.TimeOfDay.Ticks + ".bak'";
                   
                    dbConn = new System.Data.SqlClient.SqlConnection(ConnectionString);
                    dbConn.Open();
                    System.Data.SqlClient.SqlCommand dbCmd = new System.Data.SqlClient.SqlCommand(Query, dbConn);
                    dbCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    //LogError(ex);
                }
                finally
                {
                    if (dbConn.State.ToString().Equals("Open"))
                    {
                        dbConn.Close();
                    }
                    dbConn.Dispose();
                }
            }
        }
 
Share this answer
 
v3
Comments
loctrice 19-May-14 9:43am    
This code produces the exact problem the OP posted.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900