简体   繁体   English

将 MS SQL 2008 .mdf 文件转换为 .bak 文件

[英]Convert a MS SQL 2008 .mdf file to .bak file

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我尝试将 .mdf 文件转换为 .bak 文件,我一直在阅读本指南: 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.将 NameOfDatabase 替换为.... 您的数据库名称。

Replace D:\\path\\filename.bak with place you want to backup with将 D:\\path\\filename.bak 替换为您要备份的位置

Replace Name = N database name for cosmetic indexing reasons...出于装饰性索引的原因,替换名称 = N 数据库名称...

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".在服务器资源管理器中的 Visual Studio 2010 中,我选择数据连接/myDatabase.mdf 并右键单击存储过程并选择“添加新的存储过程”。 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从 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:如果我将“myDatabase”更改为“C:\\USERS\\myHome\\DESKTOP\\myPage\\APP_DATA\\MYDATABASE.MDF”,我会收到以下消息:

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?你也有LDF文件吗? 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.完成这一切的最简单方法是通过 SQL Server Management Studio。 If you don't have it (eg you're using SQL Server Express) then you should definitely download it and install it.如果您没有它(例如您正在使用 SQL Server Express),那么您绝对应该下载并安装它。 Log in to your SQL Server instance in Management Studio then在 Management Studio 中登录到您的 SQL Server 实例,然后

  • right-click on 'user databases', 'attach' then select your MDF file右键单击“用户数据库”,“附加”,然后选择您的 MDF 文件
  • right-click on the attached database and 'tasks', 'back up';右键单击附加的数据库和“任务”、“备份”; use 'remove' and 'add' in the destination box if you want to change the filename.如果要更改文件名,请在目标框中使用“删除”和“添加”。

I know this post has been for a long time but i thought also someone might still need an answer that worked for me, so The bak file is just a backup file of your SQL Server database.我知道这篇文章已经有很长时间了,但我认为有人可能仍然需要一个对我有用的答案,所以 bak 文件只是你的 SQL Server 数据库的备份文件。

You can download the MS SQL Server Express Management Console (for your version of SQL Server or SQL Server Express) and do this您可以下载 MS SQL Server Express 管理控制台(适用于您的 SQL Server 或 SQL Server Express 版本)并执行此操作

http://msdn.microsoft.com/en-us/library/ms187510.aspx http://msdn.microsoft.com/en-us/library/ms187510.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM