C# Using SMO to copy a SQL Server database under Windows 7

Posted on 2011-10-28
Last Modified: 2012-05-12

I have an application which normally runs against a SQL Server installation on a server but needs to be able to also run in a 'detached' mode whereby it runs against a local SQL Server.

This has been running happily for a while - currently I use SMO and Microsoft.SqlServer.ManagementObjects.Smo.Transfer.TransferData to copy the entire database from the remote SQL Server to a local SQL Server instance.

I have recently upgraded both my main SQL Server and my local PC to Windows 7 and on trying this operation I now get an error of :-

ERROR : errorCode=0 description=Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10_50.LIFECHECK\MSSQL\DATA\lifecheckv4.mdf" failed with the operating system error 3(failed to retrieve text for this error. Reason: 15105). helpFile= helpContext=0 idofInterfaceWithError={C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C}

This is when copying the database from my remote server to my local instance.  I have disabled the Windows Firewall on both PCs just in case that is intefering but am not at a bit of a loss to explain what the problem is.
Question by:ChrisMDrew
    LVL 96

    Accepted Solution

    That can sometimes be that the local machine does not have the same file structure as the remote server, with Backup and Restore operations.  The restore would try to put the database back in the same folder as the backup.  You said that it was running, but you didn't say if anything changed about the process, or the machine.  I am not sure how you are using SMO in this process.

    Author Closing Comment

    Thanks for this - the main issue was one which I have hit before and forgot about!  For the code to work the SQL Server instance name must be the same on both the target and source PCs - otherwise the above error is displayed.  I guess it is a 'hole' or bug in the SMO implementation.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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.

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now