SolutionsCS
asked on
Why does smo.transferdata is so long to complete.
Hi,
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.
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;
mServer.ConnectionContext.Connect();
}
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());
dbDst.Create();
// 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;
t.TransferData();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER