Hi Ashish,
Thanks for the offer of help! Here's the code in full...
using System;
using DTS;
using DTSCustTasks;
using DTSPump;
namespace ContentDatabaseDTS
{
/// <summary>
/// Class which contains code for loading database tables and data
/// </summary>
public class LoadTables
{
protected string FromServer;
protected string ToServer;
protected string DataMartDBName;
protected string OperationsDBName;
protected string ContentDBName;
protected string OutputScriptFilesPath;
protected DTS.Package2Class ContentPackage;
protected DTS.Step DataMartStep;
protected DTS.Step OperationsStep;
protected DTS.Step OperationsEmptyTablesStep;
protected DTS.PrecedenceConstraint StepPrecendence;
/// <summary>
/// constructor method for LoadTables class
/// </summary>
/// <param name="vFromServer"></param>
/// <param name="vToServer"></param>
/// <param name="vDataMartDBName"></param>
/// <param name="vOperationsDBName"></param>
/// <param name="vContentDBName"></param>
/// <param name="vOutputScriptFilesPath"></param>
public LoadTables(string vFromServer, string vToServer, string vDataMartDBName, string vOperationsDBName, string vContentDBName, string vOutputScriptFilesPath)
{
Console.WriteLine("loading from " + vDataMartDBName + " on " + vFromServer
+" and " + vOperationsDBName + " on " + vFromServer
+" into " + vContentDBName + " on " + vToServer + ", starting at " + DateTime.Now );
FromServer = vFromServer;
ToServer = vToServer;
DataMartDBName = vDataMartDBName;
OperationsDBName = vOperationsDBName;
ContentDBName = vContentDBName;
OutputScriptFilesPath = vOutputScriptFilesPath;
//create DTS package
ContentPackage = new DTS.Package2Class();
ContentPackage.Name = "Populate Content";
ContentPackage.WriteCompletionStatusToNTEventLog = false;
ContentPackage.FailOnError = false;
ContentPackage.PackagePriorityClass = DTSPackagePriorityClass.DTSPriorityClass_Normal;
ContentPackage.MaxConcurrentSteps = 4;
ContentPackage.LineageOptions = 0;
ContentPackage.UseTransaction = true;
ContentPackage.TransactionIsolationLevel = DTSIsolationLevel.DTSIsoLevel_ReadCommitted;
ContentPackage.AutoCommitTransaction = true;
ContentPackage.RepositoryMetadataOptions = 0;
ContentPackage.UseOLEDBServiceComponents = true;
ContentPackage.LogToSQLServer = false;
ContentPackage.LogServerFlags = 0;
ContentPackage.FailPackageOnLogFailure = false;
ContentPackage.ExplicitGlobalVariables = false;
ContentPackage.PackageType = 0;
//create DataMart data & tables load step
DataMartStep = ContentPackage.Steps.New();
DataMartStep.Name = "DTSStep_DTSTransferObjectsTask_1";
DataMartStep.Description = "Copy DataMart tables and data";
DataMartStep.ExecutionStatus = DTSStepExecStatus.DTSStepExecStat_Waiting;
DataMartStep.TaskName = "DTSTask_DTSTransferObjectsTask_1";
DataMartStep.CommitSuccess = false;
DataMartStep.RollbackFailure = false;
DataMartStep.ScriptLanguage = "VBScript";
DataMartStep.AddGlobalVariables = true;
DataMartStep.RelativePriority = DTSStepRelativePriority.DTSStepRelativePriority_No rmal;
DataMartStep.CloseConnection = false;
DataMartStep.ExecuteInMainThread = false;
DataMartStep.IsPackageDSORowset = false;
DataMartStep.JoinTransactionIfPresent = false;
DataMartStep.DisableStep = false;
ContentPackage.Steps.Add(DataMartStep);
//create Operations data & tables load step
OperationsStep = ContentPackage.Steps.New();
OperationsStep.Name = "DTSStep_DTSTransferObjectsTask_2";
OperationsStep.Description = "Copy Operations tables and data";
OperationsStep.ExecutionStatus = DTSStepExecStatus.DTSStepExecStat_Waiting;
OperationsStep.TaskName = "DTSTask_DTSTransferObjectsTask_2";
OperationsStep.CommitSuccess = false;
OperationsStep.RollbackFailure = false;
OperationsStep.ScriptLanguage = "VBScript";
OperationsStep.AddGlobalVariables = true;
OperationsStep.RelativePriority = DTSStepRelativePriority.DTSStepRelativePriority_No rmal;
OperationsStep.CloseConnection = false;
OperationsStep.ExecuteInMainThread = false;
OperationsStep.IsPackageDSORowset = false;
OperationsStep.JoinTransactionIfPresent = false;
OperationsStep.DisableStep = false;
ContentPackage.Steps.Add(OperationsStep);
//create Operations table definitions only load step
OperationsEmptyTablesStep = ContentPackage.Steps.New();
OperationsEmptyTablesStep.Name = "DTSStep_DTSTransferObjectsTask_3";
OperationsEmptyTablesStep.Description = "Copy Operations table definitions";
OperationsEmptyTablesStep.ExecutionStatus = DTSStepExecStatus.DTSStepExecStat_Waiting;
OperationsEmptyTablesStep.TaskName = "DTSTask_DTSTransferObjectsTask_3";
OperationsEmptyTablesStep.CommitSuccess = false;
OperationsEmptyTablesStep.RollbackFailure = false;
OperationsEmptyTablesStep.ScriptLanguage = "VBScript";
OperationsEmptyTablesStep.AddGlobalVariables = true;
OperationsEmptyTablesStep.RelativePriority = DTSStepRelativePriority.DTSStepRelativePriority_No rmal;
OperationsEmptyTablesStep.CloseConnection = false;
OperationsEmptyTablesStep.ExecuteInMainThread = false;
OperationsEmptyTablesStep.IsPackageDSORowset = false;
OperationsEmptyTablesStep.JoinTransactionIfPresent = false;
OperationsEmptyTablesStep.DisableStep = false;
ContentPackage.Steps.Add(OperationsEmptyTablesStep );
//set execution order of steps
StepPrecendence = OperationsStep.PrecedenceConstraints.New("DTSStep_ DTSTransferObjectsTask_1");
StepPrecendence.StepName = "DTSStep_DTSTransferObjectsTask_1";
StepPrecendence.PrecedenceBasis = DTSStepPrecedenceBasis.DTSStepPrecedenceBasis_Exec Result;
StepPrecendence.Value = 0;
OperationsStep.PrecedenceConstraints.Add(StepPrece ndence);
//create DataMart transfer task
DataMartTask();
//create Operations transfer task for tables and data
OperationsTask();
//create Operations transfer task for table definitions only
OperationsEmptyTablesTask();
//confirm package has been executed
Console.WriteLine("DTS package execution starting at " + DateTime.Now);
//execute package
ContentPackage.Execute();
//confirm package has been executed
Console.WriteLine("DTS package execution complete at " + DateTime.Now);
}
/// <summary>
/// prepare task to load tables and data from DataMart database into Content database
/// </summary>
private void DataMartTask()
{
// create custom data transformation task
DTS.Task oTask;
DTS.TransferObjectsTask2 oCustomTask1;
oTask = ContentPackage.Tasks.New("DTSTransferObjectsTask") ;
oCustomTask1 = (TransferObjectsTask2)oTask.CustomTask;
oCustomTask1.Name = "DTSTask_DTSTransferObjectsTask_1";
oCustomTask1.Description = "Copy DataMart";
oCustomTask1.SourceServer = FromServer;
oCustomTask1.SourceUseTrustedConnection = true;
oCustomTask1.SourceDatabase = DataMartDBName;
oCustomTask1.DestinationServer = ToServer;
oCustomTask1.DestinationUseTrustedConnection = true;
oCustomTask1.DestinationDatabase = ContentDBName;
oCustomTask1.ScriptFileDirectory = OutputScriptFilesPath;
oCustomTask1.CopyAllObjects = false;
oCustomTask1.IncludeDependencies = true;
oCustomTask1.IncludeLogins = false;
oCustomTask1.IncludeUsers = false;
oCustomTask1.DropDestinationObjectsFirst = true;
oCustomTask1.CopySchema = true;
oCustomTask1.CopyData = DTSTransfer_CopyDataOption.DTSTransfer_ReplaceData ;
oCustomTask1.ScriptOption = DTSTransfer_ScriptOption.DTSTransfer_Script_UseQuo tedIdentifiers;
oCustomTask1.ScriptOptionEx = DTSTransfer_ScriptOptionEx.DTSTransfer_ScriptEx_Tr ansferDefault;
oCustomTask1.SourceTranslateChar = true;
oCustomTask1.DestTranslateChar = true;
oCustomTask1.DestUseTransaction = false;
oCustomTask1.UseCollation = true;
//specify DataMart tables to copy
oCustomTask1.AddObjectForTransfer("AdminPIN", "dbo", DTSSQLObjectType.DTSSQLObj_UserTable);
oCustomTask1.AddObjectForTransfer("BusinessEntityS ervice", "dbo", DTSSQLObjectType.DTSSQLObj_UserTable);
....
(I won't bore you with ALL the add table statements!)
....
oCustomTask1.AddObjectForTransfer("UserReportRecip ientList", "dbo", DTSSQLObjectType.DTSSQLObj_UserTable);
//add data transfer custom task to DTS package
ContentPackage.Tasks.Add(oTask);
}
....
and of course there's two other functions for the other steps, but they're done in exactly the same way as this function.
Happy debugging!
--
cheers,
Sonya :-)
"Ashish Ruparel [MSFT]" wrote:
Quote:
Hi Sonya,
I would be glad if you can provide me the complete code it will enable me
to debug the same.
Ashish
This posting is provided "AS IS" with no warranties, and confers no rights. |