Welcome to MSDN Blogs Sign in | Join | Help

SMO Sample: Transfer

Purpose of sample: Transfer a database; all objects and data

Server tgt = new Server(".");

// Setup source connection (in this sample source is .\inst1 and target is '.' (the default instance)
Server svr = new Server(@".\inst1");
Database db = svr.Databases["testdb"];

// Setup transfer
Transfer t = new Transfer(db);
t.CopyAllObjects =
true;
t.DropDestinationObjectsFirst =
true;
t.CopySchema =
true;
t.CopyData =
true;
t.DestinationServer =
".";
t.DestinationDatabase =
"testdb";
t.Options.IncludeIfNotExists =
true;

// Do the work
t.TransferData();  // Or use ScriptTransfer() if you need to capture the script (without data)

Disclaimer: this sample doesn't handle exceptions and may not function as expected. Use at own risk. It is good practice to test an application before using it in production.

 

Published Tuesday, October 18, 2005 2:31 PM by mwories
Filed under: ,

Comments

# re: SMO Sample: Transfer

Monday, February 13, 2006 5:52 AM by Sergey Kononov
How get callback from transfer object?

# re: SMO Sample: Transfer

Monday, February 13, 2006 5:52 AM by Sergey Kononov
How get callback from Transfer object?

# re: SMO Sample: Transfer

Monday, February 25, 2008 3:28 AM by al

When I try that i get the following:

<b>Microsoft.SqlServer.Management.Smo.SmoException: The directory 'LocalApplicationData' does not exist.</b>

why?????   :-(

Anonymous comments are disabled
 
Page view tracker