Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top