Hi All,
I am getting the below error when i'm trying to edit the script component. can anyone please let me know how to resolve this error:-
Error at Data Flow Task contains script component [Script Component [566]]: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ReleaseConnections()
at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostReleaseConnections(IDTSManagedComponentWrapper100 wrapper)Object reference not set to an instance of an object. (Microsoft.SqlServer.DTSPipelineWrap)
The code in script component is as below:-
publicclassScriptMain :UserComponent
{
SqlConnectionsqlConn = newSqlConnection();
SqlCommandsqlCmd = newSqlCommand();
SqlParametersqlParam = newSqlParameter();
SqlDataReadersqlreader;
IDTSConnectionManager100connMgr;
///<summary>
/// Override the PreExecute method to prepare to save the data
///
///</summary>
publicoverridevoidPreExecute()
{
stringsqlCmdQuery = "Select * from Table1 where [Cust_Num] = @CustNum and [Contract_Id]= @ContractID";
sqlCmd = newSqlCommand(sqlCmdQuery, sqlConn);
sqlParam = newSqlParameter("@CustNum",SqlDbType.VarChar,20);
sqlCmd.Parameters.Add(sqlParam);
sqlParam = newSqlParameter("@ContractID",SqlDbType.VarChar, 40);
sqlCmd.Parameters.Add(sqlParam);
}
///<summary>
/// Override the AcquireConnections method to connect to the external data source. Extract the connection object,
/// or the required connection information, from the connection manager.
///</summary>
///<param name="Transaction"></param>
publicoverridevoidAcquireConnections(objectTransaction)
{
try
{
connMgr = this.Connections.OleDBConnMgr;;
sqlConn = (SqlConnection)connMgr.AcquireConnection(null);
}
catch(Exceptionex)
{
}
}
publicoverridevoidInput0_ProcessInputRow(Input0BufferRow)
{
sqlCmd.Parameters["@CustNum"].Value = Row.CustNum;
sqlCmd.Parameters["@ContractID"].Value = Row.Contractid;
sqlreader= sqlCmd.ExecuteReader();
}
publicoverridevoidReleaseConnections()
{
connMgr.ReleaseConnection(sqlConn);
sqlreader.Close();
}
}
Thanks -NK