什么可能导致从网络共享恢复数据库失败?

发布于 2024-10-27 17:07:05 字数 1018 浏览 9 评论 0原文

我正在使用 SQL-DMO 将位于网络共享上的数据库备份恢复到本地计算机上运行的 SQL Server 实例中。

该代码在我的机器上运行良好。但在测试虚拟机上,只有当我将备份放在本地路径中时它才有效。如果我在网络上尝试,就会失败。

我发现虚拟机上的 SQL 服务器在 系统 用户下运行,并将其更改为作为网络服务 运行,认为这是网络访问问题。但这并没有解决问题。

此代码失败,因为对 ReadFileList 的调用返回空结果集。

Dim restore As New SQLDMO.Restore With {
  .Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database,
  .ReplaceDatabase = True,
  .Database = dbName,
  .Files = "[" + backupFile + "]",
  .Devices = ""}
Dim fileList = restore.ReadFileList(sqlserver)
Dim dataLogicalName = fileList.GetColumnString(1, 1)
Dim dataPhysicalName = Path.GetFileName(fileList.GetColumnString(1, 2))
Dim logLogicalName = fileList.GetColumnString(2, 1)
Dim logPhysicalName = Path.GetFileName(fileList.GetColumnString(2, 2))

[SQL-DMO]此缓存不包含结果集,或者当前结果集包含 没有行。

在这段代码之前,我检查了 File.Exists(backupFile) 并且它通过了。但是,我知道运行此检查的进程(我的程序)与运行还原的进程(SQL Server)不同,因此不能遵循。

什么可能导致这种行为?我该如何找出服务器看不到备份文件的原因?

I'm using SQL-DMO to restore a database backup that is located on a network share into a instance of SQL Server running on the local machine.

The code works fine on my machine. But on a test VM it only works if I put the backup in a local path. If I try it on the network, it fails.

I found out the SQL server on the VM was running under the System user and changed it to run as Network Service thinking this was a problem of network access. But it didn't solve the problem.

This code fails because the call to ReadFileList returns an empty result set.

Dim restore As New SQLDMO.Restore With {
  .Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database,
  .ReplaceDatabase = True,
  .Database = dbName,
  .Files = "[" + backupFile + "]",
  .Devices = ""}
Dim fileList = restore.ReadFileList(sqlserver)
Dim dataLogicalName = fileList.GetColumnString(1, 1)
Dim dataPhysicalName = Path.GetFileName(fileList.GetColumnString(1, 2))
Dim logLogicalName = fileList.GetColumnString(2, 1)
Dim logPhysicalName = Path.GetFileName(fileList.GetColumnString(2, 2))

[SQL-DMO]This cache contains no result sets, or the current result set contains
no rows.

Before this code I do a check for File.Exists(backupFile) and it passes. However, I am aware that the process that runs this check (my program) is not the same that runs the restore (SQL Server), so it is not something to go by.

What could cause this behavior? What can I do to figure out why the server cannot see the backup file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ映画 2024-11-03 17:07:05

查看服务(开始->运行->services.msc)并向下滚动到 SQL Server。登录选项卡下的用户很可能没有共享权限。

如果 Sql Server 需要访问域资源,我建议将服务更改为以低特权域用户身份登录,以便可以为其分配对这些资源的权限。

Look in services (Start->run->services.msc) and scroll down to SQL Server. The user under the logon tab most likely does not have permission to the share.

If Sql Server is going to need access to domain resources, I'd recommend changing the service to logon as a low privileged domain user, so that it can be assigned permissions to these resources.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文