简体   繁体   English

是什么导致数据库从网络共享还原失败?

[英]What could cause database restore from a network share to fail?

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. 我正在使用SQL-DMO将位于网络共享上的数据库备份还原到在本地计算机上运行的SQL Server实例中。

The code works fine on my machine. 该代码在我的机器上正常工作。 But on a test VM it only works if I put the backup in a local path. 但是在测试VM上,只有将备份放在本地路径中才可以使用。 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. 我发现VM上的SQL Server在System用户下运行,并将其更改为以Network Service的身份运行,认为这是网络访问问题。 But it didn't solve the problem. 但这并不能解决问题。

This code fails because the call to ReadFileList returns an empty result set. 该代码失败,因为对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]This cache contains no result sets, or the current result set contains no rows. [SQL-DMO]此缓存不包含结果集,或者当前结果集不包含行。

Before this code I do a check for File.Exists(backupFile) and it passes. 在执行此代码之前,我先检查File.Exists(backupFile)并通过。 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. 但是,我知道运行此检查(我的程序)的过程与运行还原(SQL Server)的过程是不同的,因此这不是必须要做的事情。

What could cause this behavior? 是什么导致这种现象? What can I do to figure out why the server cannot see the backup file? 我该怎么办,为什么服务器看不到备份文件?

Look in services (Start->run->services.msc) and scroll down to SQL Server. 查找服务(开始->运行-> services.msc),然后向下滚动到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. 如果Sql Server将需要访问域资源,则建议将服务更改为以低特权域用户身份登录,以便可以为其分配对这些资源的权限。

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

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