Steve's profileSteve's spacePhotosBlogLists Tools Help

Blog


    October 07

    SQL 2005: SSIS - Pushing Data to MySQL using Script Component Destination

    Sometimes, I just wonder why things that are useful in previous versions of things get removed. In SQL 2000, in DTS, there was an ODBC destination, you could write (insert, update, etc) to a foreign (non MSFT SQL) system easily. DB2 – no prob, MySQL – heck yea. For whatever reason, in SQL 2005 Integration Services (SSIS), that ability was removed (in SQL 2008 SSIS there is an ADO.NET Destination that can update ODBC sources, so they brought some functionality back).

    I need to write to a MySQL database pulling data from a SQL Database, using SSIS 2005. What are the options? Well, the best I could come up with was a Script Component Destination in my DataFlow, this is how I did it:

    1) Create a new SSIS Package, throw a DataFlow on the Control Flow, Add your connections (let’s say SourceDB_SQL – your source data, and then DestDB_MySQL – your MySQL destination, it needs to be a ADO.NET Connection, you need to install the MySQL connection – I installed this http://dev.mysql.com/downloads/connector/odbc/5.1.html)

    2) In your DataFlow, create your OLEDB Source and get your query returning data, throw a Script Component on the Data Flow and make it a Destination.

    ms_01

    3) Open the Script Component, set your input columns up, and then your Connection Manager

    ms_02

    4) Open the actual script, and you just have to add a few lines of code:

    ' 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 Microsoft.SqlServer.Dts.Pipeline.Wrapper
    Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
    Imports System.Data.Odbc
     
    Public Class ScriptMain
        Inherits UserComponent
     
        Dim mySQLConn As OdbcConnection
        Dim sqlCmd As OdbcCommand
     
        Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
            mySQLConn = CType(Me.Connections.MySQLDatabase.AcquireConnection(Nothing), OdbcConnection)
        End Sub
     
        Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
     
            sqlCmd = New OdbcCommand("INSERT INTO steve_test(ShipTo, YearValue) VALUES(" & Row.ShipTo & ", '" & Row.YearValue & "')", mySQLConn)
            sqlCmd.ExecuteNonQuery()
     
        End Sub
     
        Public Overrides Sub ReleaseConnections()
            Me.Connections.MySQLDatabase.ReleaseConnection(mySQLConn)
        End Sub
    End Class
    Run it and you are done! Easy. Now you can write data into MySQL using SQL 2005 SSIS (or any ODBC destination if you can get it to work :))

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    No namewrote:
    http://www.adapterlist.com/gateway/m360.htm gateway m360 battery
    http://www.adapterlist.com/gateway/m460.htm gateway m460 battery
    http://www.adapterlist.com/hp/nc8430.htm hp nc8430 battery
    http://www.adapterlist.com/hp/dv6000.htm hp dv6000 battery
    http://www.adapterlist.com/hp/hstnn-db42.htm hp hstnn-db42 battery
    http://www.adapterlist.com/hp/dv9000.htm hp dv9000 battery
    http://www.adapterlist.com/hp/dv9700.htm hp dv9700 battery
    http://www.adapterlist.com/hp/hstnn-ib44.htm hp hstnn-ib44 battery
    http://www.adapterlist.com/hp/510.htm hp 510 battery
    http://www.adapterlist.com/hp/530.htm hp 530 battery
    http://www.adapterlist.com/sony/vgp-bps2a.htm sony vgp-bps2a battery
    http://www.adapterlist.com/sony/vgp-bps2b.htm sony vgp-bps2b battery
    http://www.adapterlist.com/sony/vgp-bps2.htm sony vgp-bps2 battery
    http://www.adapterlist.com/sony/vgp-bps2c.htm sony vgp-bps2c battery
    http://www.adapterlist.com/toshiba/pa3399u-1brs.htm toshiba pa3399u-1brs battery
    http://www.adapterlist.com/toshiba/satellite-a100.htm toshiba satellite a100 battery
    http://www.adapterlist.com/toshiba/pa3536u.htm toshiba pa3536u battery
    http://www.adapterlist.com/dell/inspiron-1300.htm dell inspiron 1300 battery
    http://www.adapterlist.com/dell/xps-1330.htm dell xps 1330 battery
    http://www.adapterlist.com/dell/xps-m1330.htm dell xps m1330 battery
    http://www.adapterlist.com/dell/inspiron-6000.htm dell inspiron 6000 battery
    http://www.adapterlist.com/dell/inspiron-9300.htm dell inspiron 9300 battery
    http://www.adapterlist.com/dell/e1705.htm dell e1705 battery
    http://www.adapterlist.com/hp/nc8230.htm hp nc8230 battery
    http://www.adapterlist.com/hp/dv9500.htm hp dv9500 battery
    http://www.adapterlist.com/hp/dv2000.htm hp dv2000 battery
    http://www.adapterlist.com/dell/latitude-d620.htm dell latitude d620 battery
    http://www.adapterlist.com/hp/dv6000.htm hp dv6000 battery
    http://www.adapterlist.com/hp/dv2700.htm hp dv2700 battery
    http://www.adapterlist.com/dell/inspiron-b130.htm dell inspiron b130 battery
    http://www.adapterlist.com/toshiba/pa3534u-1brs.htm toshiba pa3534u-1brs battery
    http://www.adapterlist.com/dell/inspiron-1525.htm dell inspiron 1525 battery
    http://www.adapterlist.com/dell/d9200.php Notebook Laptop Battery for Dell D9200 D5318 G5260 laptop battery ,
    http://www.adapterlist.com/acer/tm4200.php Battery ACER BATBL50L6 Travelmate 4200 4203 4230 4260 4280 laptop battery ,
    http://www.adapterlist.com/dell/inspiron-1200.htm dell inspiron 1200 battery
    http://www.adapterlist.com/toshiba/pa3534u-1brs.htm toshiba pa3534u-1brs battery
    http://www.adapterlist.com/toshiba/pa3399u-1bas.htm toshiba pa3399u-1bas battery
    http://www.adapterlist.com/toshiba/pa3399u-2bas.htm toshiba pa3399u-2bas battery
    http://www.adapterlist.com/gateway/m320.htm gateway m320 battery
    http://www.adapterlist.com/toshiba/satellite-a105.htm toshiba satellite a105 battery
    http://www.adapterlist.com/compaq/nc4400.htm compaq nc4400 battery
    http://www.adapterlist.com/compaq/tc4200.htm compaq tc4200 battery
    http://www.adapterlist.com/compaq/nc4200.htm compaq nc4200 battery
    http://www.adapterlist.com/dell/e1405.htm dell e1405 battery
    http://www.adapterlist.com/hp/hstnn-db02.htm hp hstnn-db02 battery
    Oct. 29

    Trackbacks

    The trackback URL for this entry is:
    http://stevienova.spaces.live.com/blog/cns!AC05D3C752D3B50A!1242.trak
    Weblogs that reference this entry
    • None