Hello All,
Am executing a stored proc with two results sets to be loaded into a flat file using script task..
Please help Am getting Exception has been thrown by the target of an invocation error.
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Below is my code. Appreciate your kind urgent help as am close to deadline.
using System;using System.IO;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
#endregion
namespace ST_bc581c6792504a7588c6fc043fde1631
{
string fpath;
string fname;
string prname;
int row = 0;
int counter = 0;
int fieldcount;
int header = 0;
DateTime startDate;
DateTime endDate;
SqlDataReader sqlreader;
SqlParameter param1 = new SqlParameter();
SqlParameter param2 = new SqlParameter();
public void Main()
{
// Read SSIS variables to local variable.
startDate = (DateTime)Dts.Variables["User::str_StartDate"].Value;
endDate = (DateTime)Dts.Variables["User::str_EndDate"].Value;
fpath = (string)Dts.Variables["User::str_Fpath"].Value;
fname = (string)Dts.Variables["User::str_Fname"].Value;
prname = (string)Dts.Variables["User::str_Pname"].Value;
// create dest ff connection
string FFConn;
FFConn = (string)(Dts.Connections["FF_DST_Details"].AcquireConnection(Dts.Transaction) as String);
StreamWriter sw = new StreamWriter(FFConn);
SqlConnection DBConn = new SqlConnection();
DBConn = (SqlConnection)(Dts.Connections["ADO_NET_ReportingOLTP"].AcquireConnection(Dts.Transaction) as SqlConnection);
SqlCommand cmd = new SqlCommand();
MessageBox.Show(DBConn.ConnectionString, "FF_DST_Details");
cmd.CommandTimeout = 300;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = prname;
param1.ParameterName = "StartDate";
param1.Value = startDate;
cmd.Parameters.Add(param1);
param2.ParameterName = "EndDate";
param2.Value = endDate;
cmd.Parameters.Add(param2);
MessageBox.Show(cmd.CommandText, "About to execute...");
if (DBConn.State == ConnectionState.Closed)
{
DBConn.Open();
sqlreader = cmd.ExecuteReader();
}
if (sqlreader.HasRows)
{
while (sqlreader.Read())
{
sw.WriteLine(sqlreader.ToString());
}
}
Dts.TaskResult = (int)ScriptResults.Success;
DBConn.Close();
sw.Close();
}
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
}