I have a script task that transfers certain passed in object from one server to another. This is the code
public void Main()
{
try
{
string schemaName = Dts.Variables["$Package::SchemaName"].Value.ToString();
string objectName = Dts.Variables["$Package::ObjectName"].Value.ToString();
//object rawETLConnection = Dts.Connections["etl"].AcquireConnection(Dts.Transaction);
//Server etlServer = (Server)rawETLConnection;
Server etlServer = new Server("ciesqldeva04");
Database etlDB;
etlDB = etlServer.Databases["sell_side_content"];
//object rawReportingConnection = Dts.Connections["reporting"].AcquireConnection(Dts.Transaction);
//Server reportingServer = (Server)rawReportingConnection;
Server reportingServer = new Server("ciesqldeva05");
Transfer xfr;
xfr = new Transfer(etlDB);
xfr.DestinationServer = reportingServer.Name;
xfr.DestinationDatabase = "sell_side_content";
xfr.DropDestinationObjectsFirst = true;
xfr.CopyAllObjects = false;
xfr.CopyData = true;
xfr.CopySchema = true;
xfr.Options.DriAll = true;
xfr.ObjectList.Add(etlDB.Tables[objectName, schemaName]);
xfr.TransferData();
}
catch (SmoException smoex)
{
Dts.Events.FireError(120, " SMO - TransferObjects.dtsx", smoex.Message, "", 0);
}
catch (Exception ex)
{
Dts.Events.FireError(120,"Non SMO - TransferObjects.dtsx",ex.Message,"",0);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
It works fine when I run it via Visual Studio 2012. But when I deploy it onto the box and run it via right clicking the package name in SSMS and hitting execute , it fail with this message "Transfer Object Using SMO:Error: An error occurred while transferring data. See the inner exception for details."
I also converted the script to a console application and running it on the box which I previously deployed the package to and running it via terminal and it was able to transfer successfully so it doesn't look like an issue of missing DLL's.
This is the code for that console application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Management.Smo;
using System.Collections.Specialized;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Server etlServer = new Server("ciesqldeva04");
Database etlDB;
etlDB = etlServer.Databases["sell_side_content"];
//object rawReportingConnection = Dts.Connections["reporting"].AcquireConnection(Dts.Transaction);
//Server reportingServer = (Server)rawReportingConnection;
Server reportingServer = new Server("ciesqldeva05");
try
{
Transfer xfr;
xfr = new Transfer(etlDB);
xfr.DestinationServer = reportingServer.Name;
xfr.DestinationDatabase = "sell_side_content";
xfr.DropDestinationObjectsFirst = true;
xfr.CopyAllObjects = false;
xfr.CopyData = true;
xfr.CopySchema = true;
xfr.Options.DriAll = true;
xfr.ObjectList.Add(etlDB.Tables["award_sector", "people"]);
xfr.TransferData();
}
catch (SmoException smoex)
{
Console.WriteLine("This is an SMO Exception");
//Display the SMO exception message.
Console.WriteLine(smoex.Message);
//Display the sequence of non-SMO exceptions that caused the SMO exception.
}
}
}
}
I have tried various things but to no success. Any help would be much appreciated.
P.S. I am running this on SQL Server 2012.