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 :
- You might be able to find this file by going to
Project --> Add
in Visual Studio, and searching for this
Reference... --> Browse
file in yourC:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
directory.
- If you can't find it there (which is what happened to me), go to the
Run...
prompt in Windows and enterC:\Windows\assembly\gac_msil
. Then, in this folder's search box, enter the file nameMicrosoft.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
精彩评论