how to convert Mdf/ldf database files to .bak file (db restore) using T-SQL or .net code

Amr Elnashar picture Amr Elnashar · Jan 6, 2011 · Viewed 7.9k times · Source

I have sql server database files (Mdf/Ldf) and i want to convert them to backup file using T-SQL commands or .net Code (C# or Vb.net).

any suggestions.

thans

Answer

Sachin Shanbhag picture Sachin Shanbhag · Jan 6, 2011
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...

Original source - http://forums.asp.net/p/1448416/3870094.aspx