NullReferenceException at SSIS Script Component
Hello Experts, I wrote a SSIS Script in the "Script Component" to extract Tabledatas from a ".txt"file into a sort componet(... just for testing after the problem persisted in my major project). It seem to be working ok because all the rows are returned in the data viewer , but keeps throwing a ("NullRefenceException": Object Reference not set to an instance of an Object) This seem not to be my Problem. All Related infos i see in Forums dont seem to be having straight foword solution Could anyone please help! I will be very greatifull ...
June 12th, 2011 3:53pm

Hello HarriUG, Not sure what you are trying to achieve or proof, but the error excerpt you posted here is typically due to an empty (not initialized array member at a specific index location referenced in your code that you try to use (e.g. set or read its value)), typically this happens during an operation like an iteration over the array members. So I am sure it is your issue. Furthermore, to investigate further we need to know the below three: The exact error message, The whole code (with stripped out or replaced sensitive data), and Let us know what do you need to solve. Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
June 12th, 2011 10:04pm

If you are trying to extrat the data from the file in a Script component you might face this issue if you assume that the data is always correct. This could happen if you are reading a lin in the file and splitting it, if the line has less than the expected number of columns you might face this issue. Put a try catch block ad redirect the error row to see if the record is correct. If not try handling it in your code. There could be other reasons as well for this to happen. Could you provide the code snippen where you are getting this error.My Blog | Ask Me | Test your SSIS skills
June 13th, 2011 6:21am

yes , if the code or algorithm is known , its easy to track the issue source. Can you please post the line where the error is ?Happy to help! Thanks. Regards and good Wishes, Deepak.
Free Windows Admin Tool Kit Click here and download it now
June 13th, 2011 9:44am

Hello, am very happy that you are all ready to help me. And below is my Code snipet: public class ScriptMain : UserComponent { private StreamReader sr ; private string addressFil; //get a connection to the file sorce public override void AcquireConnections(object Transaction) { IDTSConnectionManager100 connMgr = this.Connections.myConnectionToSource; addressFil = (string)connMgr.AcquireConnection(null) ; } //initiate a Stream Reader to start reading from the File public override void PreExecute() { base.PreExecute(); sr = new StreamReader(addressFil,false); } //Start creating reading data into the in-the-Script Component created columns public override void CreateNewOutputRows() { try { string line; while (((line = sr.ReadLine().TrimStart().TrimEnd()) != null))// remov trailling white spaces { //MessageBox.Show(addressFil + " \n" + line); if (!(line.Contains("<pre>")) && !(line.Contains("Tageswerte")) && !(line.Contains("STAT")) && !(line.Contains("---")) && !(line.Equals("")) && !(line.Contains("</pre>"))) { this.Output0Buffer.AddRow(); Output0Buffer.STAT = line.Substring(0, 5);//.TrimStart().TrimEnd(); Output0Buffer.JJJJMMTT = line.Substring(6, 8);//.TrimStart().TrimEnd(); Output0Buffer.PM = line.Substring(88, 6);//.TrimStart().TrimEnd(); } } }catch (Exception e) { MessageBox.Show("Error: " + e); } } public override void PostExecute() { sr.Close(); } }
June 15th, 2011 6:10am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics