Click here to Skip to main content
Licence CPOL
First Posted 29 May 2008
Views 24,286
Downloads 58
Bookmarked 16 times

SSIS Basic OLEDB / ODBC destination script

By | 29 May 2008 | Article
Simple destination script to use do updates with a sub query.
 
Part of The SQL Zone sponsored by
See Also

Introduction

This is a basic script for an SSIS Data Flow Script component that can be modified to execute SQL commands using an OLEDB or ODBC driver. I wanted to create this because my OLEDB command component did not let me execute an Update clause with a sub selection.

Background

I searched for some time for a simple VBScript example to just execute a query to database in SSIS. I couldn't find one, so I had to modify the MSDN example to fit my purposes.

Using the Code

What you have to do is create your SQL command using the Derived Column component or a variable. Then, add it as the input column (here, named as 'SQL_UPDATE') to the script component, and also add your connection through the Connections Manager Tab (here, named as MyConnection).

Now, the script should be ready to use.

Here is the most basic script:

Public Class ScriptMain
    Inherits UserComponent

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        '
        Dim Dest As DBDestination = New DBDestination()
        Dest.Save(Row.SQLUPDATE, Me.Connections.MyConnection.ConnectionString)

    End Sub
End Class

Public Class DBDestination

    Public Sub Save(ByVal command As String, ByVal connection As String)
        'Using cn As System.Data.Odbc.OdbcConnection = _
        '    New System.Data.Odbc.OdbcConnection(_connection)
        Using cn As System.Data.OleDb.OleDbConnection = _
                 New System.Data.OleDb.OleDbConnection(connection)
            cn.Open()
            'Dim cmd As System.Data.Odbc.OdbcCommand = cn.CreateCommand()
            Dim cmd As System.Data.OleDb.OleDbCommand = cn.CreateCommand()

            cmd.CommandType = CommandType.Text
            cmd.CommandText = command
            cmd.ExecuteNonQuery()
        End Using
    End Sub

End Class

Points of Interest

Nothing really special here. Just a basic solution to an annoying problem. But because SSIS is so easy to use, I did not want to do a lot of coding to maintain the easy maintainability that SSIS offers. Use and modify the code as you please.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

madgardener



Finland Finland

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDyanamic Excel data dump to Database ,The Excel name changes for every time Pinmemberraj kumar Arakala22:18 26 Jan '09  
QuestionSSIS Package Demo ? PinmemberPaul Chu18:59 29 Aug '08  
AnswerRe: SSIS Package Demo ? Pinmembermadgardener21:55 4 Sep '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 30 May 2008
Article Copyright 2008 by madgardener
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid