Solved

SSIS Script Component as a lookup

Posted on 2009-04-07
11
2,234 Views
Last Modified: 2013-11-10
I am testing out different way of finding information in our database through SSIS.
I put together a script transform with an ADO.NET connection and just asked it to lookup based on a sql Script similar to what I would have done in a VB application, then used teh Fuzzy Lookup to check agains the persons email and Finally used the Lookup Transform to directly compare the same scenario I used the script transform i.e. the persons employee id + company id.  The Script transform matched roughly 50% and it wasn't consistent like scipping every other row, but the lookup found them all... I want to know what I did wrogn with my script so i can have more options in the future.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.Data.SqlClient
 
Public Class ScriptMain
    Inherits UserComponent
    Dim connMgr As IDTSConnectionManager90
    Dim sqlConn As SqlConnection
    Dim sqlCmd As SqlCommand
 
 
    Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
        connMgr = Me.Connections.SQLConnection
        sqlConn = CType(connMgr.AcquireConnection(Nothing), SqlConnection)
    End Sub
 
    Public Overrides Sub PreExecute()
        sqlCmd = New SqlCommand("SELECT frid FROM frdonmst WHERE (empid = @empid) and (cmpid = @cmpid)", sqlConn)
        With sqlCmd.Parameters
            .Add("@empid", SqlDbType.VarChar, 14)
            .Add("@cmpid", SqlDbType.BigInt, 10)
        End With
        sqlCmd.CommandTimeout = 1234567890
 
    End Sub
 
 
    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        Dim reader As SqlDataReader
        Dim cmpid As Decimal = Row.EnterpriseCompanyID
        Dim empid As String = Row.EmployeeID
        sqlCmd.Parameters("@empid").Value = Row.AccountID
        sqlCmd.Parameters("@cmpid").Value = cmpid
        reader = sqlCmd.ExecuteReader()
        If reader.Read() Then
            'If (reader("Frid").ToString() Is System.DBNull.Value) Then
            '    Row.frid2_IsNull = True
            'Else
            If Row.AccountID <> "" Then
                Row.fridScript = CDec(reader("Frid").ToString())
            End If
            'End If
        End If
 
        reader.Close()
        Row.NextRow()
 End Sub
 
    Public Overrides Sub ReleaseConnections()
        connMgr.ReleaseConnection(sqlConn)
    End Sub
 
 
 
--------------------
And the lookup transform used this 
select * from
	(select * from [dbo].[frdonmst]) as refTable
where RTRIM([refTable].[cmpid]) = ? and RTRIM([refTable].[empid]) = ?
 
Parameter0 = [Enterprise Company ID]
Parameter1 = [Account ID]
 
Again the same query just two different methods of goign about it and two very different results.

Open in new window

FilePrepFridMatchingTest.xls
0
Comment
Question by:ramos_rita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 22

Expert Comment

by:PedroCGD
ID: 24088723
Why you want to replace the lookup (optimized component) by script component? DO you think you can get better performance using script component!?
Regards,
Pedro
www.pedrocgd.blogspot.com
0
 

Author Comment

by:ramos_rita
ID: 24091765
I don't think i can get better performance.
There is a unique situation that exists with our files in that there are a number of differnt unique identifiers that could exist in our system.  We process files from multiple sources.
The script uses the unique business logic that exists with each scenario to make the comparisons.
i.e. a company could have potentially 3 company ids... this is a fact we can not do away with because each id has different rules associated with them.  
So the script basically does what the lookup transform does but instead of having to put 20 lookups and stringing them together with merges and what not to keep the flow, I can just write a script that accomplishes this task.  But I don't want to do it if I can't get the same accuracy.
Thanks,
Michael
0
 
LVL 22

Expert Comment

by:PedroCGD
ID: 24095874
ok... very good! I see you understand this.
If I can help you let me know!!
Good luck!
Pedro
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:ramos_rita
ID: 24096292
Can you tell me if I am doing something wrong in the script above?
It only returns a value some of the time.  I take the same script put it in SQL and execute it and it runs perfectly.
Michael
0
 
LVL 22

Expert Comment

by:PedroCGD
ID: 24097739
but which is the error? only the output that returns one record?
Explain me better!
Thanks!
0
 

Author Comment

by:ramos_rita
ID: 24106764
If the lookup component uses the same sql script and parameters as the script component and the lookup component finds all of the records and the scritp component doesn't (roughly less than half).

Is the way I am calling the reader correct?  Is there something that I am doing in the script component that is messing with my results?

Michael
0
 
LVL 22

Expert Comment

by:PedroCGD
ID: 24155962
In perfomance I dont believe you can beat Lookup... but if you need this, ok...:-)

Now... could you send me the package, SQL scripts and some data to help you better?!
Regards,
Pedro
www.pedrocgd.blogspot.com
0
 

Author Comment

by:ramos_rita
ID: 24158174
How do I send you the package when the extension is not approved
I am changing it to .txt just change the extension back to .dtsx
FridMatching.txt
0
 

Accepted Solution

by:
ramos_rita earned 0 total points
ID: 24158510
wow...
so in the process of trying to get you some sample data I looked and though to myself... why do I need to have this Row.NextRow() in there... doesn't it send in one row at a time.
So I took out the Row.NextRow() and it seems to be working just fine.
0
 
LVL 22

Expert Comment

by:PedroCGD
ID: 24158944
also attach the script database (CREATE TABLES:...)
0
 
LVL 22

Expert Comment

by:PedroCGD
ID: 24158963
ok! good!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Throw Error 7 35
IF SQL Query 12 29
How come this XML node is not read? 3 32
SQL Server Express automatically execute SQL or SP 8 38
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question