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.
Comments
- Anonymous
February 12, 2006
How get callback from transfer object? - Anonymous
February 12, 2006
How get callback from Transfer object? - Anonymous
February 24, 2008
When I try that i get the following: <b>Microsoft.SqlServer.Management.Smo.SmoException: The directory 'LocalApplicationData' does not exist.</b> why????? :-(