开发者

How to execute SSIS package from VB.NET Windows application?

Is it possible to execute a SQL dtsx package from a Windows 2005 VB app?

If so, can someone show me how or send me a link?

I followed the instructions at: http://www.bigresource.com/Tracker/Track-ms_sql-xAKCmQKI/ but the package result was failure. 开发者_JAVA技巧Could this be because the dtsx was not on the local machine? The package works aok by itself.


Regarding DTS_E_PRODUCTLEVELTOLOW error code - see http://blogs.msdn.com/michen/archive/2006/11/11/ssis-product-level-is-insufficient.aspx



First, you need to find the file Microsoft.SqlServer.ManagedDTS.dll and add this resource into your Visual Studio project :

  1. You might be able to find this file by going to Project --> Add
    Reference... --> Browse
    in Visual Studio, and searching for this
    file in your C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies directory.


  2. If you can't find it there (which is what happened to me), go to the Run... prompt in Windows and enter C:\Windows\assembly\gac_msil. Then, in this folder's search box, enter the file name Microsoft.SqlServer.ManagedDTS.dll. Copy-paste this file into somewhere that is much easier to find, and add this reference into your Visual Studio project as mentioned above.



So, now that all of that crazy stuff is done, here's an idea of how to execute a .dtsx SSIS package in VB.NET. This is untested, with the help of someone smarter than me, whom got the idea from someone else smarter ;) :

Protected Friend Sub loadSSISPackage(ByVal packageFile As String)

    If Me.fileExists(packageFile) AndAlso packageFile.EndsWith(".dtsx") Then
        Dim pkg As New Microsoft.SqlServer.Dts.Runtime.Package
        Dim app As New Microsoft.SqlServer.Dts.Runtime.Application
        Dim pkgResults As Microsoft.SqlServer.Dts.Runtime.DTSExecResult

        pkg = app.LoadPackage(packageFile, Nothing)
        pkgResults = pkg.Execute()
        MsgBox(pkgResults.ToString())
    Else
        Environment.Exit(-1)
    End If
End Sub


you also need to set a reference (import Microsoft.SqlServer.Dts)

import Microsoft.SqlServer.Dts

Protected Friend Sub loadSSISPackage(ByVal packageFile As String)
    If Me.fileExists(packageFile) AndAlso packageFile.EndsWith(".dtsx") Then
        Dim pkg As New Microsoft.SqlServer.Dts.Runtime.Package
        Dim app As New Microsoft.SqlServer.Dts.Runtime.Application
        Dim pkgResults As Microsoft.SqlServer.Dts.Runtime.DTSExecResult

        pkg = app.LoadPackage(packageFile, Nothing)
        pkgResults = pkg.Execute()
        MsgBox(pkgResults.ToString())
    Else
        Environment.Exit(-1)
    End If
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜