-
Object reference not set to an instance of an object. - SQL Server 2005 Script
I am writing VB .NET code as a part of script when accessing the script editor in the scrit compoenet in SQL Server 2005. I am trying to read data from a flat file that is not in one of the standard formats like csv or tab delimited and when running the app I get the following error:
Object reference not set to an instance of an object.
at ScriptComponent_18cb4a15976a4641a03b8d6eb3dca3cf.ScriptMain.CreateNewOutputRows()
at ScriptComponent_18cb4a15976a4641a03b8d6eb3dca3cf.UserComponent.PrimeOutput(Int32 Outputs, Int32[] OutputIDs, PipelineBuffer[] Buffers)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PrimeOutput(Int32 outputs, Int32[] outputIDs, PipelineBuffer[] buffers)
Here is the code I am using, any input in getting this resolved will be much appreciated:
' Microsoft SQL Server Integration Services user script component
' This is your new script component in Microsoft Visual Basic .NET
' ScriptMain is the entrypoint class for script components
Imports System
Imports System.Data
Imports System.Math
Imports System.IO
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Dim path As String = "C:\\Temp\\Apple 2006-01-08-01-14 Job ZXW_00411011P Step 1.TXT"
Dim oStreamReader As StreamReader
Public Overrides Sub CreateNewOutputRows()
Dim counter As Integer
Dim sLine As String
Dim a() As String
Dim splitChar() As String
Dim cntr As Integer
splitChar(0) = "|"
splitChar(1) = " "
Try
oStreamReader = New StreamReader(path)
For counter = 1 To 5
sLine = oStreamReader.ReadLine().ToString
Next
a = sLine.ToString.Split(splitChar, StringSplitOptions.None)
Do While a(0) IsNot Nothing
Me.AppleOutputBuffer.AddRow()
Me.AppleOutputBuffer.SKUOutput = a(1)
For counter = 3 To (a.Length - 1)
If (a(counter) <> splitChar(1)) Then
Me.AppleOutputBuffer.SLoc = a(counter)
cntr = counter
Exit For
End If
Next
For counter = cntr To (a.Length - 1)
If (a(counter) <> splitChar(1)) Then
Me.AppleOutputBuffer.TransactionType = a(counter)
cntr = counter
Exit For
End If
Next
For counter = cntr To (a.Length - 1)
If (a(counter) <> splitChar(1)) Then
Me.AppleOutputBuffer.S = a(counter)
cntr = counter
Exit For
End If
Next
For counter = cntr To (a.Length - 1)
If (a(counter) <> splitChar(1)) Then
Me.AppleOutputBuffer.TransactionType = a(counter)
cntr = counter
Exit For
End If
Next
For counter = cntr To (a.Length - 1)
If (a(counter) <> splitChar(1)) Then
Me.AppleOutputBuffer.Tracking = a(counter)
cntr = counter
Exit For
End If
Next
sLine = oStreamReader.ReadLine().ToString
a = sLine.ToString.Split(splitChar, StringSplitOptions.None)
Loop
Me.AppleOutputBuffer.SetEndOfRowset()
Catch ex As Exception
Me.ComponentMetaData.FireError(1, "Script Component", ex.Message, "", 0, True)
Finally
oStreamReader.Close()
End Try
'
' Add rows by calling AddRow method on member variable called "<Output Name>Buffer"
' E.g., MyOutputBuffer.AddRow() if your output was named "My Output"
'
End Sub
End Class
Thanks,
Manisha
Similar Threads
-
By ObiWan in forum VB Classic
Replies: 3
Last Post: 05-23-2006, 10:35 AM
-
By myLittleTools.net in forum web.announcements
Replies: 0
Last Post: 03-10-2001, 01:35 PM
-
By andriano in forum Enterprise
Replies: 1
Last Post: 10-02-2000, 03:54 PM
-
By Becky in forum Database
Replies: 1
Last Post: 07-11-2000, 03:27 PM
-
By Tom Shreve in forum Enterprise
Replies: 0
Last Post: 04-07-2000, 08:15 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|