I try to convert a .mdf file to a .bak file, I have been reading this guide: http://forums.asp.net/p/1448416/3870094.aspx
BACKUP DATABASE [NameOfDatabase] TO DISK = N'D:\path\filename.bak' WITH NOFORMAT, NOINIT, NAME = N'NameOfDatabase-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
Replace NameOfDatabase with…. name of your database.
Replace D:\path\filename.bak with place you want to backup with
Replace Name = N database name for cosmetic indexing reasons…
But I get an error message when I run it.
In Visual Studio 2010 in Server Explorer I select Data Connection/myDatabase.mdf and rightclick Stored Procedure and choose “add new stored Procedure”. There I write:
BACKUP DATABASE [myDatabase] TO DISK = N'C:\db\dbCopy.bak' WITH NOFORMAT, NOINIT, NAME = N'dbCopy-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
When I select the text and run selection I get this error message:
Executing selected script from mssql:://Home\e1d5110c-dd6f-4d/C:\USERS\myHome\DESKTOP\myPage\APP_DATA\MYDATABASE.MDF/dbo/Stored Procedure/dbo/StoredProcedure1
Database 'myDatabase' does not exist. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
No rows affected.
(0 row(s) returned)
What am I doing wrong? If I change ‘myDatabase’ to ‘C:\USERS\myHome\DESKTOP\myPage\APP_DATA\MYDATABASE.MDF’ I get this message:
Database 'C:\USERS\myHome\DESKTOP\myPage\APP_DATA\MYDATABASE.MDF' does not exist. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
No rows affected.
(0 row(s) returned)
You need to attach the database first before you can back it up. Do you have an LDF file as well? You might need one, or it might be happy to build its own afresh – I’m not sure.
The simplest way to do this all is through SQL Server Management Studio. If you don’t have it (e.g. you’re using SQL Server Express) then you should definitely download it and install it. Log in to your SQL Server instance in Management Studio then