SQL Server SMO TransferData () keeps crashing
I am using TransferData method of transfer class in SMO SQL Server. I have a call running on Windows XP running SQL Server 2008 Service Pack 1 (SP1) that is trying to move a table from SQL Server 2000 to another server on an XP machine. They both use the same SQL username and password. I checked with the import / export wizard and it went fine.
The following is an exception and the event log contains an entry "ShellPackage Error".
An exception error shows the request property as empty and does not replace. I'm guessing the DTS part is failing, but I'm not sure what or why.
Exception: "ERROR: errorCode = -1073548784 description = Request execution \" \ "failed with the following error: \" Type initializer for '' threw an exception. \ "Possible reasons for failure: Problems with the request, \" ResultSet \ "property set incorrect, the parameters are set incorrectly, or the connection is incorrect. \ r \ n helpFile = helpContext = 0 idofInterfaceWithError = {C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C} "
My code:
try
{
string MasterUser = ConfigurationSettings.AppSettings["SQLUserName"];
string MasterPassword = ConfigurationSettings.AppSettings["SQLPassword"];
Server server = new Server(SourceServer);
server.ConnectionContext.LoginSecure = false;
server.ConnectionContext.Login = MasterUser;
server.ConnectionContext.Password = MasterPassword;
Database databaseSource = server.Databases[SourceDatabaseName];
Transfer transfer = new Transfer(databaseSource);
transfer.CopyAllObjects = false;
transfer.DropDestinationObjectsFirst = false;
transfer.UseDestinationTransaction = true;
if (IsBasic)
{
transfer.CopyAllDefaults = false;
transfer.Options.Indexes = false;
transfer.Options.DriAll = false;
transfer.CopyAllDefaults = false;
}
else
{
transfer.CopyAllDefaults = true;
transfer.Options.Indexes = true;
transfer.Options.DriAll = true;
transfer.CopyAllDefaults = true;
}
transfer.Options.AnsiFile = true;
transfer.Options.SchemaQualify = true;
transfer.Options.WithDependencies = false;
transfer.CreateTargetDatabase = false;
transfer.CopySchema = true;
if (CopyData)
transfer.CopyData = true;
else
transfer.CopyData = false;
transfer.DestinationServer = DestinationServer;
transfer.DestinationDatabase = DestinationDatabaseName;
transfer.DestinationLoginSecure = false;
transfer.DestinationLogin = MasterUser;
transfer.DestinationPassword = MasterPassword;
//find the able object
foreach (Table table in databaseSource.Tables)
{
if (table.Name == TableName)
{
tableToTransfer = table;
break;
}
}
transfer.Options.IncludeIfNotExists = true;
transfer.ObjectList.Add(tableToTransfer);
transfer.TransferData();
}
catch (DbException dbExp)
{
throw new FaultException(dbExp.Message);
}
catch (Exception ex)
{
throw new FaultException(ex.Message);
}
a source to share