Package wont run through VB.NET code
Hi all,
I am working on importing EXCEL sheet data to MDM staging tables using Package.
Now when I run the package manually (EXCEL file in the same location with package, and double clicking the package) then all seems to be fine.
However, when I try to execute the package via ASP VB.NET code after uploading the file then it seems to be not working.
Here is the code to run the package:
Dim pkgLocation As String
Dim pkg As New Package
Dim app As New Application
Dim pkgResults As DTSExecResult
Dim vars As Variables
pkgLocation = Server.MapPath("~/upload/Products.dtsx")
pkg.ImportConfigurationFile(Server.MapPath("~/upload/Products.dtsConfig"))
pkg = app.LoadPackage(pkgLocation, Nothing)
vars = pkg.Variables
vars("ExcelSource").Value = (Server.MapPath("~/upload/" & _
EntityUpload.FileName))
pkgResults = pkg.Execute(Nothing, vars, Nothing, Nothing, Nothing)
pkg.Dispose()
If pkgResults = DTSExecResult.Success Then
Console.WriteLine("Package ran successfully")
Else
Console.WriteLine("Package failed")
End If
Any idea where I am making mistake?
February 10th, 2011 6:16pm
Thanks for your reply..
I don't get an error per se..however, during debugging with breakpoints, I see pkgResults as Failure{1} when debugger reaches to pkg.Dispose() line
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2011 6:32pm
Thanks..
I have to admit that I don't know how to apply this try and catch statement. I am quite a n00b with VB.NET :-)
Anyway, here is the code:
Dim pkgLocation As String
Dim pkg As New Package
Dim app As New Application
Dim pkgResults As DTSExecResult
Dim vars As Variables
Try
pkgLocation = Server.MapPath("~/upload/Products.dtsx")
pkg.ImportConfigurationFile(Server.MapPath("~/upload/Products.dtsConfig"))
pkg = app.LoadPackage(pkgLocation, Nothing)
vars = pkg.Variables
vars("ExcelSource").Value = (Server.MapPath("~/upload/" & _
EntityUpload.FileName))
pkgResults = pkg.Execute(Nothing, vars, Nothing, Nothing, Nothing)
pkg.Dispose()
If pkgResults = DTSExecResult.Success Then
Console.WriteLine("Package ran successfully")
Else
Console.WriteLine("Package failed")
End If
Catch
Response.Write("error")
End Try
February 10th, 2011 6:52pm
Thanks for your link. The only turn off is that he code is in C#
well, I guess that I gotta learn to covert that code in VB.NET speak :)
Free Windows Admin Tool Kit Click here and download it now
February 11th, 2011 10:59am
Alrighty, thanks guys for the answers.
It seems that I can run the package when Excel file in pacakage is referenced as "C:\.....\products.xlsx". The problem is that the package, via ASP.NET file upload runs twice. Hence, I see the enteries in database twice. Also, this won't be the
best solution because server environment may have different structute (i.e "~/upoload/")
Now, when I defile ExcelLocation as string variable in package scope, define this variable in package configuration and then upload the excel file in the same location as package and package config file (i.e "~/upoload/") then it doesn't work.
The package runs just fine when I try to execute the package normally and data goes in its place.
Seems that I need to play with config file, and I tried everything but either it doesn't work, or it works twice..any suggestions (or shall I post my problem in appropriate forum?)
February 11th, 2011 2:25pm