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 =
t.DropDestinationObjectsFirst =
t.CopySchema =
t.CopyData =
t.DestinationServer =
t.DestinationDatabase =
t.Options.IncludeIfNotExists =

// 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.


Comments (3)

  1. Sergey Kononov says:

    How get callback from transfer object?

  2. Sergey Kononov says:

    How get callback from Transfer object?

  3. al says:

    When I try that i get the following:

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

    why?????   🙁

Skip to main content