简体   繁体   English

将database.bak从本地计算机还原到服务器

[英]Restoring the database.bak from local machine to the server

I am trying to restore the whole db with diagrams nd foreigns keys to the existing database on the server i want to replace that with the new one , I tried the following script with no success 我试图恢复整个数据库与图表nd foreigns键到服务器上的现有数据库我想用新的替换它,我尝试了以下脚本没有成功

drop database  DuxburyCaravans    
go
RESTORE DATABASE stonestore
  FROM DISK = 'C:\Program Files\Microsoft SQLServer\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\DuxburyCaravans.BAK'
  WITH MOVE 'DuxburyCaravans' TO 'D:\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DuxburyCaravans.mdf',
  MOVE 'DuxburyCaravans_log' TO 'D:\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DuxburyCaravans.LDF'

but it comes up with errors: 但它出现了错误:

Msg 3702, Level 16, State 3, Line 3 Msg 3702,Level 16,State 3,Line 3
Cannot drop database "DuxburyCaravans" because it is currently in use. 无法删除数据库“DuxburyCaravans”,因为它目前正在使用中。
Msg 3201, Level 16, State 2, Line 1 Msg 3201,Level 16,State 2,Line 1
Cannot open backup device 'C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQL\\Backup\\DuxburyCaravans.BAK'. 无法打开备份设备'C:\\ Program Files \\ Microsoft SQL Server \\ MSSQL10_50.MSSQLSERVER \\ MSSQL \\ Backup \\ DuxburyCaravans.BAK'。 Operating system error 3(failed to retrieve text for this error. Reason: 15105). 操作系统错误3(无法检索此错误的文本。原因:15105)。
Msg 3013, Level 16, State 1, Line 1 Msg 3013,Level 16,State 1,Line 1
RESTORE DATABASE is terminating abnormally. RESTORE DATABASE异常终止。

The RESTORE only works on the actual server machine - is this your own PC, or is it a separate machine?? RESTORE仅适用于实际的服务器机器 - 这是您自己的PC,还是单独的机器?

If it's a separate machine: you cannot restore a database onto a remote server from your local harddisk - you need to put the *.bak file onto a drive that the server can reach - eg the server's own local drives, or a network drive that the server has a mapping (and access) to. 如果它是一台单独的机器:您无法将数据库从本地硬盘恢复到远程服务器上 - 您需要将*.bak文件放在服务器可以访问的驱动器上 - 例如服务器自己的本地驱动器,或者网络驱动器服务器具有映射(和访问)。

The error states that database DuxburyCaravans is in use. 该错误表明数据库DuxburyCaravans正在使用中。 You can close existing connections in SQL by changing to SINGLE_USER mode 您可以通过更改为SINGLE_USER模式来关闭SQL中的现有连接

ALTER DATABASE [DuxburyCaravans] SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE [DuxburyCaravans] FROM DISK = N'C:\Path\To\Backup.bak'
ALTER DATABASE [DuxburyCaravans] SET MULTI_USER

You first need to either: 你首先需要:

  • Close all connections to the database you're trying to restore, or 关闭您尝试还原的数据库的所有连接,或
  • Using MS SQL Management Studio, connect to the remote server. 使用MS SQL Management Studio,连接到远程服务器。 Right-click on the root server node and choose Activity Monitor . 右键单击根服务器节点,然后选择“ 活动监视器” Expand Processes , right-click on each process that is using your database and choose Kill . 展开“ 进程” ,右键单击正在使用数据库的每个进程,然后选择“ 终止” Do this with caution, of course. 当然,请谨慎行事。

Now that all connections have been closed, you can restore your database. 现在所有连接都已关闭,您可以恢复数据库。

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

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