Hi,
I am using SQL server 2008.My connection manager is OLEDB Source
I am stuck with a Script Component in SSIS package and I can’t work out. Let me know what steps are the correct in order
to solve this.
At first I have just a Flat File Source and then Script Component, nothing else.
Error:
Script Component has encountered an exception in user code.
Unable to cast COM object of type 'Syatem.__Comobject' to class type 'System.Data.SqlConnection'.Instances of types that represents COM component cannot be cast to types that do not represent COM components;however they can be cast to interface as long
as the underlying COM component supports query interface calls for the IID of interface.
at SC_5d14020d33934d14afffb8262fa856dd.vbproj.ScriptMain.AcquireConnections(Object Transaction)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.AcquireConnections(Object transaction)
System.Invalid CastException.Unable to cast COM Object of type 'System._ComObject' to class type
Script Code (from Script Component):
' Microsoft SQL Server Integration Services Script Component
' Write scripts using Microsoft Visual Basic 2008.
' ScriptMain is the entry point class of the script.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlConnection
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
Dim connMgr As IDTSConnectionManager100
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlParam As SqlParameter
Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
connMgr = Me.Connections.Connection
sqlConn = CType(connMgr.AcquireConnection(Nothing), SqlConnection)
End Sub
Public Overrides Sub PreExecute()
sqlConn.Open()
sqlCmd = New SqlCommand("SELECT * FROM TestEmpS)", sqlConn)
' sqlParam = New SqlParameter("@KeyCustomer", SqlDbType.Int)
sqlCmd.Parameters.Add(sqlParam)
End Sub
Public Overrides Sub CustomerRecordsInput_ProcessInputRow(ByVal Row As CustomerRecordsInputBuffer)
Dim reader As SqlDataReader
' sqlCmd.Parameters("@KeyCustomer").Value = Row.CUNO
reader = sqlCmd.ExecuteReader()
If reader.Read() Then
'do all field comparisons here to determine if
' the record changed since the last ETL.
If (reader("Name").ToString() <> Row.Name) Then
Row.DirectRowToUpdateRecordsOutput()
Else
Row.DirectRowToIgnoreRecordsOutput()
End If
Else
Row.DirectRowToInsertRecordsOutput()
End If
reader.Close()
End Sub
Public Overrides Sub ReleaseConnections()
connMgr.ReleaseConnection(sqlConn)
End Sub
End Class
Please suggest what need to change in my code
Thanks in advance,
Regards,
Vipin jha
Thankx & regards, Vipin jha MCP