Problem to DLL

Hi,
where should I trace, due to the error shown below?
https://dl.dropboxusercontent.com/u/40211031/tt346.jpg

while line 345 within "SendExcelTask.vb" is

GenerateReport(conn, args)
...

Open in new window

LVL 11
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Is there a CreateReport method call inside the GenerateReport method? I would start there.
0
HuaMin ChenProblem resolverAuthor Commented:
Do you mean

"Is there a CreateReport method call inside Sub-routine GenerateReport?"
0
Éric MoreauSenior .Net ConsultantCommented:
yes is there a call to that method? The stack trace shows that call. And CreateReport is surely a method you have written and the error should be in there.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

HuaMin ChenProblem resolverAuthor Commented:
The process can only be scheduled to be called. How to find out the reason of the error within CreateReport?
0
Éric MoreauSenior .Net ConsultantCommented:
Open the code, add a Try ... Catch, handle the error to show more details. We need more details has your screen shot is not showing much. You need to dig down the code more to give us specific info.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HuaMin ChenProblem resolverAuthor Commented:
Do you mean to put Try ... catch around CreateReport?
0
Éric MoreauSenior .Net ConsultantCommented:
Yes. The closer you are to the error the better it is?
0
HuaMin ChenProblem resolverAuthor Commented:
I only get this StackTrace

   於 AccountingAgent.GeneralExportInterComSalesDataToSunAccount.CreateReport()
   於 AccountingAgent.ExportInterComSalesDataToSunAccount.GenerateReport(MySqlConnection dataConn, Object[] args) 於 C:\Kts Projects\KongTai\AccountingAgent\AccountingAgent\ExportInterComSalesDataToSunAccount.vb: 行 29

Open in new window

from the following

Imports OfficeOpenXml
Imports System.IO

Public Class ExportInterComSalesDataToSunAccount : Inherits SendExcelTask

    Public Sub New()
    End Sub

    Private fReportOption As ReportOption
    Public Overloads Property ReportOption() As ReportOption
        Get
            Return fReportOption
        End Get
        Set(ByVal value As ReportOption)
            fReportOption = value
        End Set
    End Property

    Public Overrides Sub OnTaskCreated(task As Kts.Agent.Core.TaskEntry)
        MyBase.OnTaskCreated(task)
        fReportOption = New ReportOption(task.ConfigNode.Node.SelectSingleNode("ReportOptions"))
    End Sub

    Protected Overrides Sub GenerateReport(dataConn As MySql.Data.MySqlClient.MySqlConnection, ParamArray args() As Object)
        Dim path As String = String.Format(OutputFolder, Now)
        Dim di As New IO.DirectoryInfo(path) : If Not di.Exists Then di.Create()
        Dim exportData As New GeneralExportInterComSalesDataToSunAccount(TheTask, ReportOption, di.FullName, dataConn)
        Try
            exportData.CreateReport()

        Catch ex As Exception
            Using writer As StreamWriter = New StreamWriter("c:\\log1.txt")
                writer.WriteLine(ex.StackTrace)

            End Using
        End Try
    End Sub
End Class

Open in new window

 
while here is CreateReport source and I cannot capture Exception StackTrace, below

Imports System.ComponentModel
Imports System.Data
Imports System.IO
Imports MySql.Data.MySqlClient
Imports OfficeOpenXml
Imports Kts.Agent.Support.ExcelReportBase
Imports Kts.Agent.Support.MySql
Imports Kts.Agent.Core.Globals
Imports OfficeOpenXml.Style

Public Class GeneralExportInterComSalesDataToSunAccount : Inherits GeneralExportDataToSunAccountBase

    Dim ds As ExportInterComSalesDataToSunAccountDataSource

    Public Sub New(task As TaskEntry, options As ReportOption, outputFolder As String, Optional ByVal conn As MySqlConnection = Nothing)
        MyBase.New(task, options, outputFolder, conn)
    End Sub

    Public Overrides Sub CreateReport()
        Try

            If CheckUserRunOption() = False Then Exit Sub
            If FromDate = #1/1/1900# Then FromDate = Now.AddDays(-1).Date
            If ToDate = #1/1/1900# Then ToDate = FromDate

            Dim conn As MySqlConnection = Kts.Agent.Support.MySql.Database.OpenConnection()
            'Dim dataRange As New DataRangeOption With {.FromDate = FromDate.Date, .ToDate = ToDate.Date,
            '                  .IsAllBrands = True, .IsAllShops = False, .ShopLine = ALL_LOCATIONS_NOMOCKUP,
            '                  .IsShopFilterByLine = True, .ShopLineCode = "", .IsAllShopInLine = True,
            '                  .IsAllProductCodes = True, .ShoesProduct = True, .AccessoriesProduct = True, .OthersProduct = True, .IsTransfer = False}

            Dim dataRange As New DataRangeOption With {.FromDate = FromDate.Date, .ToDate = ToDate.Date,
                      .IsAllBrands = True, .IsAllShops = False,
                      .IsShopFilterByLine = True, .ShopLineCode = ALL_LOCATIONS_NOMOCKUP, .IsAllShopInLine = True,
                      .IsAllProductCodes = True, .ShoesProduct = True, .AccessoriesProduct = True, .OthersProduct = True, .IsTransfer = False}

            'Start - Added by CHI 20150723

            If SelectedShopCodes IsNot Nothing AndAlso SelectedShopCodes.Count > 0 Then
                With dataRange
                    .Shops = SelectedShopCodes
                    .IsAllShops = False
                    .IsShopFilterByLine = False
                    .IsAllShopInLine = False
                End With
            End If
            'End - Added by CHI 20150723

            dataRange.ClearExcludes()
            If ReportOption.SalesExcludeShops.Count > 0 Then dataRange.ExcludeShops.AddRange(ReportOption.SalesExcludeShops)
            If ReportOption.SalesExcludeWareTypes.Count > 0 Then dataRange.ExcludeWarehouseTypes.AddRange(ReportOption.SalesExcludeWareTypes)

            Dim dataRangeCollection As New DataRangeOptionCollection
            dataRangeCollection.Add(dataRange)

            Task.SubDescription = "正在讀取數據..."

            ds = New ExportInterComSalesDataToSunAccountDataSource(dataRangeCollection, ReportOption.GetDatabases, conn)
            TotalLoadedRows += ds.LoadReportData
            CloseConnection(conn)

            For Each companyCode In ds.Select(Function(x) x.CompanyCode).Distinct
                For Each journalCode In ds.Where(Function(x) x.CompanyCode.Equals(companyCode, StringComparison.OrdinalIgnoreCase)).Select(Function(x) x.JournalCode).Distinct
                    GenerateFile(companyCode, journalCode, dataRangeCollection)
                Next
            Next
        Catch ex As Exception
            Using writer As StreamWriter = New StreamWriter("c:\\log2.txt")
                writer.WriteLine(ex.StackTrace)
            End Using
        End Try
    End Sub

Open in new window

what to check?
0
HuaMin ChenProblem resolverAuthor Commented:
Here is SendExcelTask
Imports System.ComponentModel
Imports System.Net.Mail
Imports System.Text.RegularExpressions
Imports MySql.Data.MySqlClient
Imports Kts.Agent.Core
Imports Kts.Agent.Support.MySql

Public Delegate Function SendMailRequireFunc(receiver As MailReceiverNode) As Boolean

Public Enum MailSendType
    GeneralUser = 0
    ManagementUser
End Enum

Public MustInherit Class SendExcelTask : Inherits AgentTask

#Region " Constructor "
    Public Sub New()
        TranslateWords.Set("{date}", "0")
    End Sub
#End Region

    Public Event ImmediateRun(sender As Object, e As ImmediateRunEventArgs)
    Public Event MailFinialize(sender As Object, e As MailFinializeEventArgs)

    Private fTranslateWords As New CustomVariables
    Public ReadOnly Property TranslateWords As CustomVariables
        Get
            Return fTranslateWords
        End Get
    End Property

    Public Overrides ReadOnly Property Icon As System.Drawing.Bitmap
        Get
            Return My.Resources.file_extension_xls
        End Get
    End Property

    Private fConsolePage As New ConsolePanel
    Public ReadOnly Property ConsolePage As ConsolePanel
        Get
            Return fConsolePage
        End Get
    End Property

    Public Overrides ReadOnly Property ConsolePageControl As System.Windows.Forms.Control
        Get
            Return fConsolePage
        End Get
    End Property

    Private WithEvents fSetupPage As New SendMailSetupPanel
    Public ReadOnly Property SetupPage As SendMailSetupPanel
        Get
            Return fSetupPage
        End Get
    End Property

    Public Overrides ReadOnly Property SettingPageControl As System.Windows.Forms.Control
        Get
            Return fSetupPage
        End Get
    End Property

    Private fOutputPath As String = Application.StartupPath
    Public ReadOnly Property OutputFolder As String
        Get
            Return String.Format(TranslateText(fOutputPath), ProcessDate)
        End Get
    End Property

    Public ReadOnly Property ConfigOutputPath As String
        Get
            Return fOutputPath
        End Get
    End Property

    Private fReportOption As ReportOptionNode
    Public ReadOnly Property ReportOption As ReportOptionNode
        Get
            Return fReportOption
        End Get
    End Property

    Private fEmailReceivers As BindingList(Of MailReceiverNode) = Nothing
    Public ReadOnly Property EmailReceivers As BindingList(Of MailReceiverNode)
        Get
            Return fEmailReceivers
        End Get
    End Property

    Private fEmailClient As MailServerNode = Nothing
    Public ReadOnly Property EmailClient As MailServerNode
        Get
            Return fEmailClient
        End Get
    End Property

    Private fMailSender As New MailAddress("notification@kts-group.com", "店鋪通知系統")
    Public ReadOnly Property MailSender As MailAddress
        Get
            Return fMailSender
        End Get
    End Property

    Private fIsHtmlBody As Boolean = False
    Public Property IsHtmlBody() As Boolean
        Get
            Return fIsHtmlBody
        End Get
        Set(ByVal value As Boolean)
            fIsHtmlBody = value
        End Set
    End Property

    Private fPriority As MailPriority = MailPriority.Normal
    Public Property Priority() As MailPriority
        Get
            Return fPriority
        End Get
        Set(ByVal value As MailPriority)
            fPriority = value
        End Set
    End Property

    Private fMailBodyMessage As String = "此電郵是經由寫字樓自動報表系統發送到店鋪的, 請勿回覆此電郵!" & vbCrLf & "如有任何疑問, 請與電腦部聯絡! 謝謝!" & vbCrLf & vbCrLf & "《自動報表發佈系統》"
    Public Property MailBodyMessage() As String
        Get
            Return fMailBodyMessage
        End Get
        Set(ByVal value As String)
            fMailBodyMessage = value
        End Set
    End Property

    Private fMailSubject As String = "(無主旨)"
    Public Property MailSubject() As String
        Get
            Return fMailSubject
        End Get
        Set(ByVal value As String)
            fMailSubject = value
        End Set
    End Property

    Protected Property IsDebug As Boolean

    Protected Property IsNoMail As Boolean

    Protected Property SendFakeMail As Boolean

    Protected Overridable Sub OnMailFinialize(e As MailFinializeEventArgs)
        RaiseEvent MailFinialize(Me, e)
    End Sub

    Public Function TranslateText(text As String) As String
        Dim rtv As String = text
        For Each word In TranslateWords
            Dim src As String = word.Name
            Dim replaceAs As String = word.Value.ToString
            rtv = Regex.Replace(rtv, "(?i)" & src, replaceAs)
        Next
        Return rtv
    End Function

    Public Function TranslateUpperText(text As String) As String
        Dim rtv As String = text
        For Each word In TranslateWords
            Dim src As String = word.Name
            Dim replaceAs As String = word.Value.ToString.ToUpper
            rtv = Regex.Replace(rtv, "(?i)" & src, replaceAs)
        Next
        Return rtv
    End Function

    Public Function TranslateLowerText(text As String) As String
        Dim rtv As String = text
        For Each word In TranslateWords
            Dim src As String = word.Name
            Dim replaceAs As String = word.Value.ToString.ToLower
            rtv = Regex.Replace(rtv, "(?i)" & src, replaceAs)
        Next
        Return rtv
    End Function

    Public Function GetFullFilename(reportName As String, Optional customValue() As Object = Nothing, Optional extension As String = ".xlsx") As String
        Dim path As String = OutputFolder & IIf(OutputFolder.EndsWith("\"), "", "\")
        Dim custom() As Object = {ProcessDate}
        If customValue IsNot Nothing Then custom = custom.Union(customValue).ToArray
        Return path & String.Format(TranslateText(reportName), custom) & extension
    End Function

    Public Function CreateExcelFile(filename As String) As ExcelPackage
        Dim fi As New IO.FileInfo(filename) : If fi.Exists Then fi.Delete()
        If Not fi.Directory.Exists Then fi.Directory.Create()
        Return New ExcelPackage(fi)
    End Function

    Public Sub SaveExcelFile(package As ExcelPackage)
        package.Save()
        package.Dispose()
    End Sub

    Public Overrides Sub OnTaskCreated(task As Kts.Agent.Core.TaskEntry)
        fOutputPath = task.ConfigNode.GetAttributeString("OutputFolder", fOutputPath)
        fReportOption = New ReportOptionNode(task.ConfigNode.Node.SelectSingleNode("ReportOptions"))
        fEmailClient = New MailServerNode(task.ConfigNode.Node.SelectSingleNode("MailServer"))
        Dim sender As XmlNode = task.ConfigNode.Node.SelectSingleNode("MailSender")
        If sender IsNot Nothing Then fMailSender = New MailAddressNode(sender).MailAddress
        fEmailReceivers = MailReceiverNode.GetReceiverList(task.ConfigNode)
        fConsolePage.Title.Text = task.Description
        fConsolePage.Messages.Columns(2).Width = 300
        With fSetupPage
            .Task = task
            .SetControlsValue(ConfigOutputPath, EmailClient, MailSender, ReportOption, False, EmailReceivers)
            .FolderSetup.FolderEntryToolTip = ""
        End With
    End Sub

    Protected ProcessDate As Date
    Protected ZipFilename As String = "{{date}:yyyy-MM-dd}"
    Protected DeleteZipAfterSend As Boolean = True

    Protected Sub SendGeneralUserEmail(Optional attachFilenames() As String = Nothing,
                                       Optional keyValue As String = "",
                                       Optional subject As String = "",
                                       Optional bodyText As String = "",
                                       Optional receiverValidate As SendMailRequireFunc = Nothing)
        Dim email As New Net.Mail.MailMessage
        If attachFilenames IsNot Nothing AndAlso attachFilenames.Length > 0 Then
            For Each p In attachFilenames
                email.Attachments.Add(New Net.Mail.Attachment(p))
            Next
        End If
        email.From = MailSender
        email.Subject = If(String.IsNullOrEmpty(subject.Trim), MailSubject, subject)        
        email.IsBodyHtml = IsHtmlBody
        email.Priority = Priority
        email.Body = If(String.IsNullOrEmpty(bodyText.Trim), MailBodyMessage, bodyText)
        For Each receiver As MailReceiverNode In fEmailReceivers
            If Not receiver.Enabled OrElse receiver.IsMenegementUser Then Continue For
            If receiverValidate IsNot Nothing AndAlso Not receiverValidate(receiver) Then Continue For
            Dim emailAddress As MailAddress = receiver.MailAddress(Function(x) TranslateLowerText(x),
                                                                   Function(x) TranslateUpperText(x))
            Select Case receiver.ReceiveType
                Case MailReceiverType.Normal : email.To.Add(emailAddress)
                Case MailReceiverType.Cc : email.CC.Add(emailAddress)
                Case Else
                    email.Bcc.Add(emailAddress)
            End Select
        Next
        OnMailFinialize(New MailFinializeEventArgs(email, MailSendType.GeneralUser))
        If email.To.Count > 0 Then
            Try
                If Not SendFakeMail Then EmailClient.SmtpServer.Send(email)
                TheTask.WriteSendMailLog(email, TranslateText("【{log.prefix}】電郵已成功" & If(SendFakeMail, "模擬", "") & "發送"))
            Catch ex As Exception
                TheTask.WriteSendMailLog(email, TranslateText("【{log.prefix}】發送電郵出錯!"), ex)
            End Try
        Else
            TheTask.WriteLog(TranslateText("【{log.prefix}】沒有收件人或主要收件人"))
        End If
        For Each item In email.Attachments
            item.Dispose()
        Next
        email.Dispose()
    End Sub

    Protected Sub SendGeneralUserEmail(attachFilename As String,
                                       Optional keyValue As String = "",
                                       Optional subject As String = "",
                                       Optional bodyText As String = "",
                                       Optional receiverValidate As SendMailRequireFunc = Nothing)
        SendGeneralUserEmail({attachFilename}, keyValue, subject, bodyText, receiverValidate)
    End Sub

    Private Sub SendManagementEmail()
        Dim mailUsers As MailReceiverNode() = fEmailReceivers.Where(Function(x) x.IsMenegementUser AndAlso x.Enabled).ToArray
        If TheTask.ProduceObjects.Count > 0 AndAlso (mailUsers IsNot Nothing AndAlso mailUsers.Length > 0) Then
            Dim path As String = System.IO.Path.GetTempPath : If Not path.EndsWith("\") Then path &= "\"
            Dim zipFilename As String = path & TranslateText(Me.ZipFilename) & ".zip"
            TheTask.SubDescription = "正在建立壓宿檔案... "
            Dim zipFi As System.IO.FileInfo = TheTask.ZipProduceAsFiles(zipFilename, 9)
            If zipFi IsNot Nothing Then
                Dim attachment As New Net.Mail.Attachment(zipFi.FullName)
                Dim email As New Net.Mail.MailMessage
                email.From = MailSender
                email.Attachments.Add(attachment)
                email.Subject = MailSubject
                email.IsBodyHtml = IsHtmlBody
                email.Priority = Priority
                email.Body = MailBodyMessage
                For Each receiver As MailReceiverNode In mailUsers
                    Dim emailAddress As MailAddress = receiver.MailAddress
                    Select Case receiver.ReceiveType
                        Case MailReceiverType.Normal : email.To.Add(emailAddress)
                        Case MailReceiverType.Cc : email.CC.Add(emailAddress)
                        Case Else
                            email.Bcc.Add(emailAddress)
                    End Select
                Next
                OnMailFinialize(New MailFinializeEventArgs(email, MailSendType.ManagementUser))
                If email.To.Count > 0 Then
                    Try
                        If Not SendFakeMail Then EmailClient.SmtpServer.Send(email)
                        TheTask.WriteSendMailLog(email, TranslateText("【壓宿文件】電郵已成功" & If(SendFakeMail, "模擬", "") & "發送"))
                    Catch ex As Exception
                        TheTask.WriteSendMailLog(email, TranslateText("【壓宿文件】發送電郵出錯!"), ex)
                    End Try
                Else
                    TheTask.WriteLog("【壓宿文件】沒有收件人或主要收件人")
                End If
                email.Dispose()
                attachment.Dispose()
                If DeleteZipAfterSend Then zipFi.Delete()
            End If
        End If
    End Sub

    Protected MustOverride Sub GenerateReport(dataConn As MySqlConnection, ParamArray args() As Object)

    Public Overrides Function Execute(Task As Core.TaskEntry, ParamArray args() As Object) As Core.TaskResult
        IsDebug = False
        IsNoMail = False
        SendFakeMail = False
        If Task.IsImmediateRun Then
            Dim e As New ImmediateRunEventArgs
            RaiseEvent ImmediateRun(Me, e)
            IsDebug = e.IsDebugMode
            IsNoMail = e.IsNoMail
            SendFakeMail = e.SendFakeMail
            If e.Cancel Then Return TaskResult.NotExecute
        End If
        Dim rtv As TaskResult = TaskResult.Successed
        Dim conn As MySqlConnection = Nothing
        Try
            fConsolePage.ConsoleData.Clear()
            fConsolePage.ConsoleData.AddConsoleMessage("工作開始")
            Task.StartLog()
            Task.BeginSubDescriptionUpdate()
            conn = OpenConnection(ReportOption)
            fConsolePage.ConsoleData.AddConsoleMessage("連線碼: " & conn.ConnectionString)
            ProcessDate = Now
            Task.ProduceObjects.Clear()
            GenerateReport(conn, args)
            If Not IsNoMail AndAlso Not IsDebug AndAlso TheTask.ProduceObjects.Count > 0 Then SendManagementEmail()
            Task.SubDescription = "工作執行完成"
            Task.EndSubDescriptionUpdate()
            fConsolePage.ConsoleData.AddConsoleMessage("工作完成")
        Catch ex As Exception
            Task.WriteLog(String.Format("執行錯誤: {0}", ex.Message))
            Globals.SystemMessages.Add(String.Format("{0} 執行錯誤", Description), ex.ToString & vbCrLf & "At Line: " & Erl())
            Task.LastError = ex
            rtv = TaskResult.Failed
        Finally
            CloseConnection(conn)
            Task.EndLog()
        End Try
        Return rtv
    End Function

    Private Sub fSetupPage_ConfigSaved(sender As Object, e As System.EventArgs) Handles fSetupPage.ConfigSaved
        With CType(SettingPageControl, SendMailSetupPanel)
            TheTask.Description = .Title
            TheTask.AutoStart = .AutoStart
            fOutputPath = .FolderSetup.EditPath
            fMailSender = New MailAddress(.SmtpSetup.SenderEmail, .SmtpSetup.SenderName)
            fEmailClient = New MailServerNode(TheTask.ConfigNode.SelectSingleNode("MailServer").Node)
            ReportOption.DataSource = .DataSourceSetup.GetDataSource
            ReportOption.DataServer = .DataServerSetup.ServerName
            ReportOption.DataUser = .DataServerSetup.UserId
            ReportOption.DataPassword = .DataServerSetup.Password
            fEmailReceivers = MailReceiverNode.GetReceiverList(Me.TheTask.ConfigNode)
        End With
    End Sub
End Class

Public Class MailFinializeEventArgs : Inherits EventArgs
    Public Sub New(mail As MailMessage, userType As MailSendType)
        fMail = mail
        fUserType = userType
    End Sub

    Private fUserType As MailSendType
    Public ReadOnly Property UserType As MailSendType
        Get
            Return fUserType
        End Get
    End Property

    Private fMail As MailMessage
    Public ReadOnly Property Mail As MailMessage
        Get
            Return fMail
        End Get
    End Property
End Class

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.