Kiran
Kiran

Reputation: 8528

OS error 3 when backing up database

It is a follow-up question to my previous question in the same forum.

I would like to take a backup of my SQL Server database. Here is the code, for the backup in C#.

userConn = new SqlConnection(userdatabase);
userConn.Open();

string UserString;

UserString = "BACKUP DATABASE @DBName TO  DISK = @FilePath";

String destPath = DestDirectory + "\\UserDataTable.bak";
SqlCommand cmd = new SqlCommand(UserString, userConn);

cmd.Parameters.AddWithValue("@dbName", userConn.Database);
cmd.Parameters.AddWithValue("@FilePath", destPath);

cmd.ExecuteNonQuery();
cmd.Dispose();

However, it throws an SQLException,

"Cannot open backup device 'D:\BookKeeping\Database\11_01_2013_21_15\Database\UserDataTable.bak'. Operating system error 3(failed to retrieve text for this error. Reason: 15105). BACKUP DATABASE is terminating abnormally."

Any Idea, what could be wrong ?

Thanks a lot for your time and your help.

Upvotes: 1

Views: 10088

Answers (2)

Subha Das
Subha Das

Reputation: 11

Make sure your SqlServer and the location where you want to create a backup is the same system. If you are using sqlServer remotely(Not located in your system) then you can not create a backup in your machine or you can not restore the database taking a .bak from your machine also.

Upvotes: 1

Richard Deeming
Richard Deeming

Reputation: 31198

"Operating system error 3" means that the directory was not found. SQL will not create the backup directory for you; you have to manually create it before running the backup command.

Upvotes: 6

Related Questions