• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

VB.NET SMO SQL SERVER 2008 Error

I am having a issue restoring my database through my vb.net program here is the code I am using

Dim res As Restore = New Restore()
res.Devices.AddDevice(backupLoc + databaseName + ".bak", DeviceType.File)
res.Database = realDBName
res.ReplaceDatabase = True
res.PercentCompleteNotification = 1
AddHandler res.PercentComplete, AddressOf ProgressEventHandler
res.SqlRestore(srv1)


The error its spitting out is
directory look up for the file .....MSSQL\Data\dbtest.mdf" failed with the oporating system error 3(The system could not find the path specified)


But if i go do a manual backup through sql managment tool it works fine.
Any ideas why it would be looking for the mdf.
0
scprogs
Asked:
scprogs
1 Solution
 
reb73Commented:
I think the issue may be in restoring the .mdf/.ldf files to the default path..

You could try explicitly specifying the location of .mdf/.ldf files using the RelocateFiles method of the Restore class..

The link below has the C# equivalent code using RelocateFiles (which you should be able to adapt for vb.net)

http://www.codeproject.com/KB/database/BackupRestoreWithSmo.aspx
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now