I am having problems making backup of database from the website itself. I've tried several solutions out there, including trying to make a stored procedure & executing it.
Almost in all the solutions I had a sort of similar problem:
Cannot open backup device 'd:\backupdb\20121224.bak'. Operating system error 21(The device is not ready.). BACKUP DATABASE is terminating abnormally.
The solutions I've liked & tried so far (listing 2 which looks most relible to me):
http://forums.asp.net/t/1561085.aspx (PLEASE SEE POST 2 IN THIS LINK)
So, maybe if anyone of you have some quite simple idea? Or solution to my problem? I'll be very thankful! :)
Thanks in advance. Awaiting eagerly.
Regards,
Hash
Hash is someone who likes to speak of himself in the third person. He is an IT enthusiast and loves working in asp.net programming, designing websites, robotics etc. Hash is the founder & COO of Azoora Inc., a web design & development agency, which provides modern websites. In his spare time, Hash enjoys learning new things, whether fixing a motorcycle, learning his violin, bulding robots, though he really enjoys killing time in garden, or stepping in hills.
Thanks for the reply. I tried that already. But didnt work. The same old error.
The site is on a shared server, is that something to do with this ? Please advice. I've gone nuts solving it :P
Thanks again!
Regards,
Hash
Hash is someone who likes to speak of himself in the third person. He is an IT enthusiast and loves working in asp.net programming, designing websites, robotics etc. Hash is the founder & COO of Azoora Inc., a web design & development agency, which provides modern websites. In his spare time, Hash enjoys learning new things, whether fixing a motorcycle, learning his violin, bulding robots, though he really enjoys killing time in garden, or stepping in hills.
I tried the same thing on localhost but the problem is persistant here as well. I dont think its a drive permission or disk full error?
Maybe something missing in the code, can you guys go through it once ? Thanks:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Management.Smo;
using System.Configuration;
using Microsoft.SqlServer.Management.Common;
using System.Web.Configuration;
public partial class Administration_Configuration_DataManagement_Backup : System.Web.UI.Page
{
//Metioned here your database name
string dbname = "themight";
SqlConnection sqlcon = new SqlConnection();
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
string CurrentPath = HttpContext.Current.Request.PhysicalPath;
Label1.Text = CurrentPath;
}
protected void StartBackup_Click(object sender, EventArgs e)
{
//Mentioned Connection string make sure that user id and password sufficient previlages
sqlcon.ConnectionString = @"Server=64.71.180.27;database=" + dbname + ";uid=nl_autobot;pwd=******;";
//Enter destination directory where backup file stored
string destdir = "C:\\Inetpub\\vhosts\\themight\\Core\\Uploads\\Images";
//Check that directory already there otherwise create
if (!System.IO.Directory.Exists(destdir))
{
System.IO.Directory.CreateDirectory("C:\\Inetpub\\vhosts\\themight\\Core\\Uploads\\Images");
}
try
{
sqlcon.Open();
//query to take backup database
sqlcmd = new SqlCommand("backup database themight to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon);
sqlcmd.ExecuteNonQuery();
//Close connection
sqlcon.Close();
SuccessPanel.Visible = true;
}
catch (Exception ex)
{
exMessage.Text = ex.ToString();
ErrorPanel.Visible = true;
}
}
}
Hash is someone who likes to speak of himself in the third person. He is an IT enthusiast and loves working in asp.net programming, designing websites, robotics etc. Hash is the founder & COO of Azoora Inc., a web design & development agency, which provides modern websites. In his spare time, Hash enjoys learning new things, whether fixing a motorcycle, learning his violin, bulding robots, though he really enjoys killing time in garden, or stepping in hills.
hash.moody
0 Points
9 Posts
Problem in Backing up database.
Dec 24, 2012 04:44 PM|LINK
Hi there,
I am having problems making backup of database from the website itself. I've tried several solutions out there, including trying to make a stored procedure & executing it.
Almost in all the solutions I had a sort of similar problem:
Cannot open backup device 'd:\backupdb\20121224.bak'. Operating system error 21(The device is not ready.). BACKUP DATABASE is terminating abnormally.
The solutions I've liked & tried so far (listing 2 which looks most relible to me):
So, maybe if anyone of you have some quite simple idea? Or solution to my problem? I'll be very thankful! :)
Thanks in advance. Awaiting eagerly.
Regards,
Hash
oned_gk
All-Star
31824 Points
6512 Posts
Re: Problem in Backing up database.
Dec 25, 2012 12:25 AM|LINK
Try give full permission to sql service account for SQL Server Service to that folder.
If you are not sure, try give full access to everyone user.
hash.moody
0 Points
9 Posts
Re: Problem in Backing up database.
Dec 25, 2012 05:30 AM|LINK
Hi oned_gk,
Thanks for the reply. I tried that already. But didnt work. The same old error.
The site is on a shared server, is that something to do with this ? Please advice. I've gone nuts solving it :P
Thanks again!
Regards,
Hash
geniusvishal
Star
14308 Points
2821 Posts
Re: Problem in Backing up database.
Dec 25, 2012 05:55 AM|LINK
The reason might me there may be no space in your D drive or try using another user account in windows with full authorization..
I recommend you to go through these threads:
http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/021c7aa5-4a8a-4bbb-8ff0-fe6b03920aae/
http://www.tek-tips.com/viewthread.cfm?qid=1591745
My Website
www.dotnetvishal.com
hash.moody
0 Points
9 Posts
Re: Problem in Backing up database.
Dec 25, 2012 06:04 AM|LINK
I tried the same thing on localhost but the problem is persistant here as well. I dont think its a drive permission or disk full error?
Maybe something missing in the code, can you guys go through it once ? Thanks:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.IO; using Microsoft.SqlServer.Management.Smo; using System.Configuration; using Microsoft.SqlServer.Management.Common; using System.Web.Configuration; public partial class Administration_Configuration_DataManagement_Backup : System.Web.UI.Page { //Metioned here your database name string dbname = "themight"; SqlConnection sqlcon = new SqlConnection(); SqlCommand sqlcmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); protected void Page_Load(object sender, EventArgs e) { string CurrentPath = HttpContext.Current.Request.PhysicalPath; Label1.Text = CurrentPath; } protected void StartBackup_Click(object sender, EventArgs e) { //Mentioned Connection string make sure that user id and password sufficient previlages sqlcon.ConnectionString = @"Server=64.71.180.27;database=" + dbname + ";uid=nl_autobot;pwd=******;"; //Enter destination directory where backup file stored string destdir = "C:\\Inetpub\\vhosts\\themight\\Core\\Uploads\\Images"; //Check that directory already there otherwise create if (!System.IO.Directory.Exists(destdir)) { System.IO.Directory.CreateDirectory("C:\\Inetpub\\vhosts\\themight\\Core\\Uploads\\Images"); } try { sqlcon.Open(); //query to take backup database sqlcmd = new SqlCommand("backup database themight to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon); sqlcmd.ExecuteNonQuery(); //Close connection sqlcon.Close(); SuccessPanel.Visible = true; } catch (Exception ex) { exMessage.Text = ex.ToString(); ErrorPanel.Visible = true; } } }oned_gk
All-Star
31824 Points
6512 Posts
Re: Problem in Backing up database.
Dec 25, 2012 06:11 AM|LINK
Open log viewer to determine what the problem.
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: Problem in Backing up database.
Dec 27, 2012 06:26 AM|LINK
Hi,
I have tested your code locally and find out it works well locally as follows:
public partial class Default178 : System.Web.UI.Page { string dbname = "testdatabase"; SqlConnection sqlcon = new SqlConnection(); SqlCommand sqlcmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); protected void Page_Load(object sender, EventArgs e) { string CurrentPath = HttpContext.Current.Request.PhysicalPath; Label1.Text = CurrentPath; } protected void Button1_Click(object sender, EventArgs e) { //Mentioned Connection string make sure that user id and password sufficient previlages sqlcon.ConnectionString = @"Server=.\sqlexpress;database=" + dbname + ";Integrated Security=True"; //Enter destination directory where backup file stored string destdir = "E:\\Project\\WebSite5\\backupSql"; //Check that directory already there otherwise create if (!System.IO.Directory.Exists(destdir)) { System.IO.Directory.CreateDirectory("E:\\Project\\WebSite5\\backupSql"); } try { sqlcon.Open(); //query to take backup database sqlcmd = new SqlCommand("backup database testdatabase to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon); sqlcmd.ExecuteNonQuery(); //Close connection sqlcon.Close(); Response.Write("success1"); } catch (Exception ex) { Response.Write( ex.ToString()); } } }In order to resolve your issue, please make sure the Network Service has the write permission on the folder you are trying to backup.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store