I am trying to create a backup of my SQL Server Database in Visual Studio 2010.
I am using the following command to back up the database:
BACKUP DATABASE Db TO DISK = ‘c:\server.bak’
This is connection string that I am using.
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Db.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
However, when I run the command, I get the following error message.
Database ‘Db’ does not exist.
Here is a screenshot that describes my error:
http://www.cs.purdue.edu/homes/aerfanfa/sqlerror.jpg
Does anyone have a solution for my problem?
Thanks!
The problem is: your database
db.mdfis not attached to the SQL Server Express instance – therefore, you cannot back it up.This whole
AttachDbFileName=.....story is a bit tricky – and quite a mess, if you ask me.I would recommend to just forget about using that
AttachDbFileName=...stuff, and instead:just attach the
db.mdffile to your local SQL Server Express instance (using SQL Server Management Studio Express)talk to the attached database using it’s logical database name instead of messing around with a
.mdffileOnce you’ve done that – then you can use commands like
BACKUP DATABASE ...and everything else!Your connection string would be much simpler, too!