SMO Sample: Transfer

Published 18 October 05 02:31 PM | mwories 

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.

 

Filed under: ,

Comments

# Sergey Kononov said on February 13, 2006 5:52 AM:
How get callback from transfer object?
# Sergey Kononov said on February 13, 2006 5:52 AM:
How get callback from Transfer object?
# al said on February 25, 2008 3:28 AM:

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