• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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