How to back up and restore the localDb 2012 database?
I am trying to backup my localDB file using the method file.Copy()
, but it produces the following IOException
:
The process cannot access the file '. \ DB.mdf' because it is in use by another process.
And when I try to make a backup with the following script:
@"BACKUP DATABASE " + DatabaseName + " TO DISK = N'" + BackUpLocation + @"\" + BackUpFileName + @"'"
it outputs the following SqlException
:
The database "DB" does not exist. Make sure the name is entered correctly.
My connection string:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DB.mdf;Integrated Security=True;Connect Timeout=30
What is the best way to make a backup in this situation?
+3
source to share