Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

SSIS 2012 Package Failing at Script task

$
0
0

Background:
I have a project done in Integration Services 2012. The purpose of the SSIS package is to replace the Data Driven Subscriptions provided by the more expensive versions of SSRS. An ASP.NET web application is the front end, and has multiple departments with email lists associated to each department... The SSIS package checks to see if there is any data for the report, so the email doesn't contain an empty pdf. Then it compiles the "To" string with the emails specific to that department.

Then in the script task it performs two tasks:
1) Cleans up the network share of all pdf files
2) Connects to the SSRS web service and generates the report that is then exported to pdf in the network share directory.

Finally, if the pdf exists, the package emails it to the list of emails generated in a string. So basically it is a drawn out way to replace the Data Driven Subscriptions that certain versions of SSRS offer.

Problem:
The problem is with one server in particular. I have this package installed on 4 different SQL Server instances and working 100%, every morning at 8AM it runs without error or issues. However, I have to put it into production on an instance that refuses to execute it successfully. The package sends out an email on failure, so I added a variable to the script task to catch the exception and include it in the failure email. I get an error when attempting to access the network share directory, and when attempting to access the SSRS service. As I said before, this package works everywhere but at this location. I cannot debug from my box, because the package executes perfect from Visual Studio. So I turn to the SQL Server community. Below are my two exceptions and my script task code. I cannot help but thinking the SQL Server is missing something, maybe a library required to execute the Script Task. I have added the domain account that is used by the SQL Service to the SSRS server and the network share with full permissions, and I have even tried .NET Impersonation in the script task, and while the Impersonation works, the script task still fails with the same error. 

Errors:

System.IO.IOException: Logon failure: unknown user name or bad password.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler)
   at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
   at ST_489cafcbe82c45eb9f591b14e21080ff.ScriptMain.Main()

System.Net.WebException: The request failed with HTTP status 401: Unauthorized.
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at ST_489cafcbe82c45eb9f591b14e21080ff.ReportServer.ReportExecutionService.LoadReport(String Report, String HistoryID)
   at ST_489cafcbe82c45eb9f591b14e21080ff.ScriptMain.Main()

Script Task Source Code:

    Public Sub Main()
        Try
            Try
                For Each _File As String In Directory.GetFiles(Path.GetDirectoryName(Dts.Variables("User::FullFilePath").Value.ToString), "*.pdf", SearchOption.AllDirectories)
                    File.Delete(_File)
                Next
            Catch ex As UnauthorizedAccessException
                Dts.Variables("User::ErrorOutput").Value = Dts.Variables("User::ErrorOutput").Value.ToString() + " " + ex.ToString()
                Error (1)
            End Try

            Dim objRSExec As New ReportServer.ReportExecutionService
            Dim objParamDepartment As New ReportServer.ParameterValue

            Dim objParams(1) As ReportServer.ParameterValue

            Dim objResult() As Byte
            Dim objStream As FileStream

            Dim strFileType As String
            Dim strFileExtension As String
            Dim strFullPathName As String

            strFileType = Dts.Variables("User::FileType").Value.ToString
            strFileExtension = Dts.Variables("User::FileExtension").Value.ToString
            strFullPathName = Dts.Variables("User::FullFilePath").Value.ToString

            With objParamDepartment
                .Name = "DepartmentId"
                .Value = Dts.Variables("User::DepartmentID").Value
            End With

            objParams(0) = objParamDepartment

            With objRSExec
                .Credentials = System.Net.CredentialCache.DefaultCredentials
                .Url = Dts.Variables("User::ReportServer").Value.ToString + "reportexecution2005.asmx"
                .LoadReport(Dts.Variables("User::ReportName").Value.ToString, Nothing)
                .SetExecutionParameters(objParams, "en-us")
                objResult = .Render(strFileType, Nothing, strFileExtension, Nothing, Nothing, Nothing, Nothing)
            End With

            objStream = File.Create(strFullPathName, objResult.Length)

            With objStream
                .Write(objResult, 0, objResult.Length)
                .Close()
            End With

            Dts.Variables("User::FileExists").Value = File.Exists(Dts.Variables("User::FullFilePath").Value.ToString)

            Dts.TaskResult = ScriptResults.Success
        Catch ex As Exception
            Dts.Variables("User::ErrorOutput").Value = Dts.Variables("User::ErrorOutput").Value.ToString() + " " + ex.ToString()
            Error (1)
        End Try
    End Sub


Viewing all articles
Browse latest Browse all 24688

Trending Articles