We help IT Professionals succeed at work.

Why does smo.transferdata is so long to complete.

I want to to create copy of a specific databases using smo object.  I found many examples of code explaining how to do it with transferdata method, but it is extremly slow.  The database is around 200 MB and itt take 20 minutes to complete on a dual core with 2 gig of ram.  My Server is local.  I tried to use restore database and it appear to be very quick.  Since i have to be able to create multiple copy of the database source and number them, it would be more logic to make copy instead of restore.  What's wrong with it?  Do i miss an operation?  Do i use the good method?

Here is the parameters define in settings of the application.
DbPrefix is the databasename to use a source.
NextSuffix is the next number of the copy.
ServerName is the name of the server to use.
public SQLManagement ()
      mServer= new Server();
      mServer.ConnectionContext.DatabaseName = Properties.Settings.Default.DBPrefix;
      mServer.ConnectionContext.AutoDisconnectMode = AutoDisconnectMode.NoAutoDisconnect;
      mServer.ConnectionContext.BatchSeparator = "GO";
      mServer.ConnectionContext.ServerInstance = Properties.Settings.Default.ServerName;
      mServer.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteAndCaptureSql;
      mServer.ConnectionContext.ConnectTimeout = 5;
      mServer.ConnectionContext.LoginSecure = true;
    public void CreateCopy()
      // Crée la base de données de destination
      Database dbSrc = mServer.Databases[Properties.Settings.Default.DBPrefix];
      Database dbDst = new Database( mServer, Properties.Settings.Default.DBPrefix + Properties.Settings.Default.NextSuffix.ToString());
      // Setup transfer(All objects Data and Schema)
      Transfer t = new Transfer(dbSrc);
      t.CopyAllTables = true;
      t.Options.WithDependencies = true;
      t.Options.ContinueScriptingOnError = true;
      t.DestinationDatabase = dbDst.Name;
      t.DestinationServer = mServer.Name;
      t.DestinationLoginSecure = true;
      t.CopySchema = true;
      t.CopyData = true;

Open in new window

Watch Question

Senior Database Administrator

I just saw this question get answered, and thought that the info in it might help.



I got an alternative solutions effectively, but it's still does not explain why it is slow and if there is a way to optimize it?  35 minute on my last try with TransferData over a database of approximatively 200 megs...  In the sql 2005 wizard it take 20 seconds????  The goal of this is to produce an environment of Unitary test for software.  Any other comment or idea would be of great help.