We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Using SMO to copy an SQL database

ChrisMDrew
ChrisMDrew asked
on
Medium Priority
279 Views
Last Modified: 2013-12-16
I have a requirement to perform a large number of updates within a SQL database from C#.  Essentially I am merging changes made to one copy of a database into a master database.

I originally was thinking of using a transaction but this would not work in my case as the merge calls loads of stored procedures and sql queries which create their own connection.

I then decided to create a backup copy of the database being updated, update the copy, delete the original database and rename the copy to ensure that if anything went wrong during the update that my master database was left intact.

I am using the SMO classes to create the copy of the main database and have hit a problem - even though I have changed the name of the new database the SMO classes seem to want to create the same file names for the .MDF and .LDF files which then give an error from the call to

transfer.TransferData()

Are there any options which I can specify on the transfer which will change the names of the physical files created?  I have specified that the new database should be created if it does not exist.
Comment
Watch Question

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thanks - just what I needed
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.