使用新名称将数据库恢复到新服务器
我正在尝试使用 C# 和 SQL 服务器数据库创建数据库备份并将其恢复到具有新名称的新服务器。我可以创建数据库的备份,但无法使用新名称将其恢复到新服务器。
我的查询看起来像这样: 它不起作用并出错:
RESTORE DATABASE test1 FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\setupdb\BackupForsetupdb.bak'
WITH MOVE 'setupdb_Data' TO '\\newserver\e$\MSSQL\DATA\test1_Data.MDF',
MOVE 'setupdb_log' TO '\\newserver\e$\MSSQL\DATA\test1_Log.LDF';
我试图通过 C# 代码实现此目的。看起来数据库无法恢复到远程服务器。请对此进行一些说明。
谢谢!
I am trying to create backup and restore of a database to new server with new name using C# and SQL server database. I can create a backup of the database but I am not able to restore it to the new server using the new name.
My query looks something like this: it doesn't work and errors out:
RESTORE DATABASE test1 FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\setupdb\BackupForsetupdb.bak'
WITH MOVE 'setupdb_Data' TO '\\newserver\e$\MSSQL\DATA\test1_Data.MDF',
MOVE 'setupdb_log' TO '\\newserver\e$\MSSQL\DATA\test1_Log.LDF';
I am trying to achieve this through C# code.It looks like the database cannot be restored to the remote servers. Please throw some light on this.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您不能在网络共享上拥有 SQL Server 数据库:仅限本地/SAN 类型驱动器
备份文件可以位于共享上,但 MDF 和 LDF 必须位于本地
有一个 MS 知识库文章:可以完成,但风险自负
You can't have SQL Server databases on network shares normally: local/SAN type drives only
The backup file can be on a share but the MDF and LDFs must be local
There is an MS KB article on it: it can be done but at your own risk
移动命令的路径必须相对于服务器。
并且您从路径的恢复也必须相对于服务器。如果
c:\
来自本地计算机,您需要将其指向 UNC 路径 (\\yourpc\c$\...
) 或将其移动到服务器。但请注意,如果使用 UNC 路径选项,则运行服务器进程的用户也必须具有访问共享的权限。因此,您最好复制到远程计算机上的驱动器。Your paths for the move command have to be relative to the server.
And your restore from path has to be relative to the server as well. If the
c:\
is from your local machine, you either need to point it to a UNC path (\\yourpc\c$\...
) or move it to the server. But be aware that if using the UNC path option, the user the server process is running as has to have permissions to access the share as well. So you're probably better off copying to a drive on the remote computer.