Posted on 2009-04-17
Last Modified: 2013-11-26
I am having a issue restoring my database through my 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

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.
Question by:scprogs
    1 Comment
    LVL 25

    Accepted Solution

    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

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now