Hi
I used the code below to backup from SQLEXPRESS
SqlConnection con = new SqlConnection(@"Data Source=.\SQLExpress;User Instance=true;Integrated Security=True;Initial Catalog=[myDb];AttachDBFilename='" + DbPath + "'");
SqlCommand com = new SqlCommand("BACKUP DATABASE [myDb] TO DISK = N'" + BackupPath + "'",con);
com.Connection.Open();
com.ExecuteNonQuery();
com.Connection.Close();
But I get this exception :
Database 'myDb' does not exist. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
And when I change sqlconnection to this:
SqlConnection con = new SqlConnection(@"Data Source=.\SQLExpress;User Instance=true;Integrated Security=True;Initial Catalog=[myDb];AttachDBFilename='" + DbPath + "';database=myDb");
I get this exception :
Unable to open the physical file "C:\Users\MohammadHG\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\bin\Debug\Database\db.mdf". Operating system error 32: "32(failed to retrieve text for this error. Reason: 15105)".
Cannot attach the file 'C:\Users\MohammadHG\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\bin\Debug\Database\db.mdf' as database 'myDb'.
I used to connect and execute SQLCommands allover my application without any problems, I just have problem with backup and restore.
please help me...