如何使用T-SQL或.net代码将Mdf/ldf数据库文件转换为.bak文件(db restore)

Amr*_*har 5 sql-server mdf ldf database-restore

我有sql server数据库文件(Mdf/Ldf),我想使用T-SQL命令或.net代码(C#或Vb.net)将它们转换为备份文件.

有什么建议.

thans

Sac*_*hag 3

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...
Run Code Online (Sandbox Code Playgroud)

原始来源 - http://forums.asp.net/p/1448416/3870094.aspx