locked
creating back up of database RRS feed

  • Question

  • User-2112725598 posted

    Hi all

    I had created a website and i am able to get backup of database on local system by this code

     protected void ImageBackup_Click(object sender, ImageClickEventArgs e)
        {
            DatabaseBackup("C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe", "newpos");
            ClientScript.RegisterStartupScript(this.GetType(), "Key", "alert('Back up has been Successfully created on desktop')", true);
        } public void DatabaseBackup(string ExeLocation, string DBName)
        {
            try
            {
                string tmestr = "";
                tmestr = DBName + "-" + DateTime.Now.ToShortDateString() + ".sql";
                tmestr = tmestr.Replace("/", "-");
                tmestr = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + tmestr;
                StreamWriter file = new StreamWriter(tmestr);
                ProcessStartInfo proc = new ProcessStartInfo();
                string cmd = string.Format(@"-u{0} -p{1} -h{2} {3}", "root", "root", "localhost", DBName);
                proc.FileName = ExeLocation;
                proc.RedirectStandardInput = false;
                proc.RedirectStandardOutput = true;
                proc.Arguments = cmd;
                proc.UseShellExecute = false;
                Process p = Process.Start(proc);
                string res;
                res = p.StandardOutput.ReadToEnd();
                file.WriteLine(res);
                p.WaitForExit();
                file.Close();
            }
            catch (IOException ex)
            {

            }
        }

    but when i'm creating back up from website then i'm not able to create backup

    so please guide me in creating backup

    thanks in advance

    Friday, April 5, 2013 1:57 AM

All replies

  • User197322208 posted

    remove try/catch and let the error flow

    Friday, April 5, 2013 2:52 AM
  • User-2112725598 posted

    I am getting error like

    Server Error in '/' Application.


    Access to the path 'C:\newpos-4-5-2013.sql' is denied.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [UnauthorizedAccessException: Access to the path 'C:\newpos-4-5-2013.sql' is denied.]
       System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10760710
       System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1352
       System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +66
       System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) +73
       System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) +124
       System.IO.StreamWriter..ctor(String path) +34
       Store_Config_PosStoreConfig.DatabaseBackup(String ExeLocation, String DBName) +133
       Store_Config_PosStoreConfig.ImageBackup_Click(Object sender, ImageClickEventArgs e) +26
       System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
       System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +124
       System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
    


    Friday, April 5, 2013 3:47 AM
  • User197322208 posted

    Access to the path 'C:\newpos-4-5-2013.sql' is denied.

    Ok. So either change the path, either let app pool user have access to the folder.

    Friday, April 5, 2013 7:37 AM