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

Posted on 2011-10-28
Medium Priority
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

Bob Learned earned 2000 total points
ID: 37049472
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

ID: 37061690
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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

809 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