0

VB.NET 3.5 sp1 コンソール アプリケーションを Windows XP sp3 でバッチ ファイルから実行しています。

"D:\Program Files\PartsDepotJob\PartsDepotJob.exe" >> "D:\Program Files\PartsDepotJob\partdepot.log.txt"

出力は次のようになります。

2/10/2009 9:03:19 AM
処理 PO#: 2100 in 002
Created OE# 135
Processing PO#: 2100 in 003
Created OE# 136
DONE
2/10/2009 9:03:30 AM
Processing PO#: 2100 002
作成 OE# 137
処理 PO#: 2100 で 003
作成 OE# 138
DONE

ただし、クライアントで Windows 2003 sp2 (.NET 3.5 sp1 も使用) ボックスで同じことを実行すると、出力が次のように文字化けします。

2009 年 2 月 9 日 4:03:37 PM 完了 2009 年 2 月 9 日 4:04:06 PM 完了 2009 年 2 月 9 日
4:11:01 PM 完了 2009 年 2 月9 日 4:30:23 PM 処理 PO# : 702 の 1649400 Created OE# 1/1/1900 4:30:26 PMCreated OE# 49 1/1/1900 4:30:26 PMProcessing PO#: 1649500 in 702 Created OE# 49 1/1/1900 4:30 :28 PMCreated OE# 50 1/1/1900 4:30:28 PMDONE











つまり、CrLf が削除されることがあり、出力の前に 1900 年 1 月 1 日 {time} が付けられているように見えることがあります。

これを引き起こす原因について何か考えはありますか?

関連するコードは次のとおりです。

Imports Wisys.AllSystem
Imports Wisys.Oe
Imports Wisys.Po
Imports System.Configuration
Imports System.Data
Imports System.Linq

Public Class clsPartsDepot
    Private wsConn As Wisys.AllSystem.ConnectionInfo = Nothing
    Private wsPartDepotSalesOrd As Wisys.Oe.OrderEntryTables = Nothing

    Public Function ProcessPartDepotOrders() As Boolean
        Dim errMsg As String = ""
        Try
            Console.WriteLine(Now().ToString)
            ''//sendBadPOLineEmailtoDepot("test")
            Dim dsPO As New Data.DataSet
            Dim dbName As String = ""
            Dim dbServer As String
            Dim partDepotDbName As String = ConfigurationManager.AppSettings("partDepotDbName")
            Dim partDepotDbServer As String = ConfigurationManager.AppSettings("partdepotDBserver")
            Dim KeyName As String = ""
            Dim billToCompany As String ''//, billtoCompAddr1 As String
            Dim dtBillTo As DataTable
            Dim i As Integer = 1


            Dim appkeyQry = From key In ConfigurationManager.AppSettings Where key Like "CompanyDbName*" Select key

            ''//for each company database look for PO's
            For Each KeyName In appkeyQry
                dbName = ConfigurationManager.AppSettings(KeyName)
                dbServer = ConfigurationManager.AppSettings("CompanyDbServer" & i)
                billToCompany = ConfigurationManager.AppSettings(dbName)

                dtBillTo = GetCustomer(billToCompany, partDepotDbName, partDepotDbServer)
                If dtBillTo.Rows.Count = 0 Then
                    Throw New Exception("Customer record for company database '" & dbName & "' not found in the parts depot!")
                End If
                ''//billtoCompAddr1 = dtBillTo.Rows(0)("cmp_fadd1")

                ''//get all the unprocessed, printed PO's from the current company.
                dsPO = GetPoDataset(dbName, dbServer)

                If IsNothing(dsPO) Then
                    Console.WriteLine("Error processing part depot: " & errMsg)
                    Exit Function
                End If

                Dim itemNum As String, qtyOrd As Double, requestDate As Date, promiseDate As Date, lineNum As String, itemPrice As Double
                Dim errNum As Integer = 0
                Dim poNum As String = ""
                ''//for each unprocessed, printed PO in the current company
                For Each dr As DataRow In dsPO.Tables(0).Rows

                    If poNum <> dr("ord_no") Then
                        Console.WriteLine("Processing PO#: " & dr("ord_no") & " in " & dbName)

                        If Not poNum = "" Then 'for first run don't close it, not open
                            wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg)
                            wsConn.Dispose()
                            wsConn = Nothing
                        End If
                        wsConn = New Wisys.AllSystem.ConnectionInfo
                        OpenWiSysConn(partDepotDbName, partDepotDbServer, True)

                        If Not poNum = "" Then 'for first run don't Dispose it; already equal to nothing
                            If Not IsNothing(wsPartDepotSalesOrd) Then wsPartDepotSalesOrd.Dispose()
                            wsPartDepotSalesOrd = Nothing
                        End If
                        wsPartDepotSalesOrd = New Wisys.Oe.OrderEntryTables
                        wsPartDepotSalesOrd.Connection(wsConn, errMsg)

                        With wsPartDepotSalesOrd.OrderHeader
                            .UserName = My.User.Name
                            .Ship_to_name = If(IsDBNull(dr("cmp_name")), "", dr("cmp_name"))
                            .Ship_to_addr_1 = If(IsDBNull(dr("cmp_fadd1")), "", dr("cmp_fadd1"))
                            .Ship_to_addr_2 = If(IsDBNull(dr("cmp_fadd2")), "", dr("cmp_fadd2"))
                            .Ship_to_addr_3 = If(IsDBNull(dr("cmp_fadd3")), "", dr("cmp_fadd3"))
                            .Ship_to_addr_4 = If(IsDBNull(dr("cmp_fcity")), "", dr("cmp_fcity")) & " , " & _
                            If(IsDBNull(dr("StateCode")), "", dr("StateCode"))
                            .Ship_to_country = If(IsDBNull(dr("cmp_fcounty")), "", dr("cmp_fcounty"))
                            .Oe_po_no = dr("ord_no")
                        End With

                        ''//wsPartDepotSalesOrd.OrderHeader.Status 'readonly
                        errNum = wsPartDepotSalesOrd.OrderHeader.Insert(TrxEnums.OeOrderTypeEnum.Order, "", billToCompany, "", dr("ord_dt"), errMsg)
                        If errNum <> 0 Then
                            Console.WriteLine("Error Creating OE header:" & errMsg)
                        Else
                            Console.WriteLine("Created OE#" & wsPartDepotSalesOrd.OrderHeader.Ord_no)
                        End If
                    End If
                    poNum = dr("ord_no")

                    ''//if error then skip to the next loop iteration until the next PO # and it gets inserted ok
                    If errNum <> 0 Then
                        Continue For
                    End If

                    lineNum = If(IsDBNull(dr("line_no")), Now(), dr("line_no"))
                    itemNum = dr("item_no").ToString
                    qtyOrd = If(IsDBNull(dr("qty_ordered")), 0, CDbl(dr("qty_ordered")))
                    requestDate = If(IsDBNull(dr("request_dt")), Now(), dr("request_dt"))
                    promiseDate = If(IsDBNull(dr("promise_dt")), Now(), dr("promise_dt"))
                    itemPrice = If(IsDBNull(dr("price")), 0, dr("price"))

                    If itemNum.Length > 0 And qtyOrd <> 0 Then
                        CreateLine(wsPartDepotSalesOrd, itemNum, qtyOrd, 0, requestDate, requestDate, promiseDate, itemPrice, poNum)
                        ''//mark as processed, even if above fails. any lines that fail will be added to SO in parts depot by hand.
                        markPoLineAsProcessed(dbName, dbServer, poNum, lineNum)
                    End If

                Next
                poNum = ""
                i = +1
                If Not IsNothing(wsConn) Then
                    wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg)
                    wsConn.Dispose()
                End If
                If Not IsNothing(wsPartDepotSalesOrd) Then wsPartDepotSalesOrd.Dispose()
                wsConn = Nothing
                wsPartDepotSalesOrd = Nothing
            Next
            Console.WriteLine("DONE")

        Catch ex As Exception
            Console.WriteLine("Exception processing part depot: " & ex.Message)

        Finally
            Try
                ''//cleanup 
                If Not IsNothing(wsPartDepotSalesOrd) Then
                    wsPartDepotSalesOrd.Dispose()
                    wsPartDepotSalesOrd = Nothing
                End If

                If Not IsNothing(wsConn) Then
                    wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg)
                    wsConn.Dispose()
                    wsConn = Nothing
                End If
            Catch ex As Exception
                Console.WriteLine("Exception exiting part depot: " & ex.Message)
            End Try
        End Try
    End Function

    Private Function GetCustomer(ByVal CustomerNum As String, ByVal db As String, ByVal server As String) As DataTable
        Dim cn As New SqlClient.SqlConnection
        Dim cmd As New SqlClient.SqlCommand
        Dim da As New SqlClient.SqlDataAdapter
        Dim ds As New DataSet
        Try
            cn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=" & db & ";server=" & server
            cn.Open()
            cmd = cn.CreateCommand
            cmd.Parameters.Add(New SqlClient.SqlParameter("@cusnum", CustomerNum))
            cmd.CommandText = "select cmp_name,cmp_fadd1,coalesce(debnr,crdnr) as CusNum from dbo.cicmpy where ltrim(debnr) = @cusnum or ltrim(crdnr) = @cusnum"
            cmd.CommandType = CommandType.Text
            da.SelectCommand = cmd
            da.Fill(ds)
            If ds.Tables.Count > 0 Then
                Return ds.Tables(0)
            End If
            Return Nothing
        Finally
            If Not IsNothing(cmd) Then cmd.Dispose()
            If Not IsNothing(cn) Then cn.Dispose()
            If Not IsNothing(da) Then da.Dispose()
        End Try
    End Function

    Private Function GetPoDataset(ByVal db As String, ByVal server As String) As DataSet
        Dim cn As New SqlClient.SqlConnection
        Dim ds As New DataSet
        Dim dsa As New SqlClient.SqlDataAdapter
        Dim cmd As New SqlClient.SqlCommand
        Try
            Static Dim SQL As String = ConfigurationManager.AppSettings("getPoforPartsDepotSQL")
            cn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=" & db & ";server=" & server
            cn.Open()
            cmd.Connection = cn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = SQL
            dsa.SelectCommand = cmd
            dsa.Fill(ds)
            Return ds
        Catch
            Throw
        Finally
            If Not IsNothing(ds) Then ds.Dispose()
            If Not IsNothing(cmd) Then cmd.Dispose()
            If Not IsNothing(cn) Then cn.Close()
            If Not IsNothing(cn) Then cn.Dispose()
        End Try
    End Function

    Private Function OpenWiSysConn(ByVal dbName As String, ByVal dbServer As String, ByVal useTran As Boolean) As Boolean
        Try
            Dim errMsg As String = ""

            wsConn.Parameters(dbServer, dbName, "MacMSS")

            If wsConn.OpenWisysConnection(useTran, errMsg) <> 0 Then
                Console.WriteLine("Error processing part depot: " & errMsg)
                Return False
            End If

            Return True
        Catch
            Throw
        End Try
    End Function

    Private Function CreateLine(ByVal p_oOEObj As Wisys.Oe.OrderEntryTables, ByVal partNum As String, ByVal qtyOrdered As Double, ByVal qtyToShip As Double, ByVal RequestDate As Date, ByVal RequestShipDate As Date, ByVal PromiseDate As Date, ByVal price As Double, ByVal PONum As String) As Boolean
        Dim OeLine As OEORDLIN
        Dim p_sRtnErrMsg As String = ""
        Dim p_lRtnVal As Long
        Dim p_lRtnLineNumber As Long

        With p_oOEObj
            ''//p_lRtnVal = .OrderHeader.Read(TrxEnums.OeOrderTypeEnum.Order, p_sRtnOrder, True, True, True, p_bRtnRecFound, p_sRtnErrMsg)

            OeLine = .OrderHeader.OrderLines.Add(TrxEnums.OrderLineType.InventoryItem, partNum.ToUpper, "", qtyOrdered, qtyToShip, price, price, RequestDate, PromiseDate, RequestShipDate, True, p_sRtnErrMsg)

            p_lRtnVal = OeLine.Insert(p_lRtnLineNumber, p_sRtnErrMsg)


            If p_lRtnVal = 0 Then
                Return True
            End If

            Console.WriteLine("Error creating sales order line# " & p_lRtnLineNumber & ": " & p_sRtnErrMsg)
            sendBadPOLineEmailtoDepot("Error creating sales order line for PO# " & PONum & " becuase of an error: " & p_sRtnErrMsg)
            Return False

        End With
    End Function

    Private Function markPoLineAsProcessed(ByVal DB As String, ByVal server As String, ByVal poOrdNum As String, ByVal poLineNum As String) As Boolean
        Dim cn As New SqlClient.SqlConnection
        Dim cmd As New SqlClient.SqlCommand
        Try
            Static Dim SQL As String = ConfigurationManager.AppSettings("markPoLineAsSendToDepotSQL")

            cn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=" & DB & ";server=" & server & ";"
            cn.Open()
            cmd.Connection = cn
            cmd.Parameters.Add(New SqlClient.SqlParameter("@poOrdNum", poOrdNum))
            cmd.Parameters.Add(New SqlClient.SqlParameter("@poLineNum", poLineNum))
            cmd.CommandType = CommandType.Text
            cmd.CommandText = SQL
            cmd.ExecuteNonQuery()
            Return True
        Catch
            Throw
        Finally
            If Not IsNothing(cmd) Then cmd.Dispose()
            If Not IsNothing(cn) Then cn.Dispose()
        End Try
    End Function

    Private Function sendBadPOLineEmailtoDepot(ByVal msgText As String) As Boolean
        Try
            If ConfigurationManager.AppSettings("EnableSentBadPOMail").ToLower <> "true" Then Return True
            Dim sMailServer As String = ConfigurationManager.AppSettings("MailServer")
            Dim mySmtpClient As New System.Net.Mail.SmtpClient(sMailServer)
            mySmtpClient.UseDefaultCredentials = True
            mySmtpClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
            Dim sTo As String = ConfigurationManager.AppSettings("BadPOMailTo")
            Dim sFrom As String = ConfigurationManager.AppSettings("BadPOMailFrom")


            mySmtpClient.Send(sFrom, sTo, msgText, msgText)

            Return True
        Catch ex As Exception
            Console.WriteLine("Exception sending sending bad PO line e-mail to depot: " & ex.Message)
            Return False
        End Try
    End Function

End Class  

更新:出力を上書きしたくありません。追加したいです。したがって、>> ではなく >

更新: コンソール ウィンドウの見通しは同じです。ファイルにリダイレクトされない場合。これは、このファイルに出力するアプリケーションであり、一度に 1 つのみ実行されます。クライアント データベースに不良データはないようです。

サイト間のコードは同じであると確信しています。また、問題を引き起こす余分な console.write/writeline がないことを確認しました。

更新: 関連する可能性のあるコードがいくつかありませんでした。上記のコード スニペットを更新しました。

更新: クライアントでプロセスを「手動で」実行しているので、1 つしか実行されていなかったと確信しています。ProcessPartDepotOrders() は、sub main() から 1 回呼び出されるだけなので、スレッドの問題は見当たりません。

4

2 に答える 2

1

Ifではなく新しい方を使ってよくやっIIfた。ただし、コードには、まだ vb6 からのスローバックである他の構成要素がいくつかあります。最大の特徴は、新しい AndAlso 演算子により、実際のコントロール/ブレーク スタイルのループ構造を使用できることです。.Net でオブジェクトを破棄した後に Nothing に設定する必要もありません。Usingキーワードを使用して、破棄と finally ブロックをより適切に処理できます。また、.Net スタイル ガイドラインでは、's' や ' cls'.

それを利用するためにコードを自由に再構築したので、ここから始めます。先に進む前に、このリファクタリングによって新しいバグが発生していないことを確認したいと思います。

アップデート:

リファクタリングされたコードをすべて表示するように私の投稿を更新しました。簡単な名前の変更、接続文字列の除外、OpenWiSysConn() 関数の動作の変更に注意してください。

Public Class PartsDepot
    Public Function ProcessPartDepotOrders() As Boolean
        Dim errMsg As String = ""
        Try
            Console.WriteLine(Now)
            ''//sendBadPOLineEmailtoDepot("test")
            Dim POData As New DataSet
            Dim dbName As String = ""
            Dim dbServer As String
            Dim partDepotDbName As String = ConfigurationManager.AppSettings("partDepotDbName")
            Dim partDepotDbServer As String = ConfigurationManager.AppSettings("partdepotDBserver")
            Dim KeyName As String = ""
            Dim billToCompany As String ''//, billtoCompAddr1 As String
            Dim dtBillTo As DataTable


            Dim i As Integer = 1
            Dim appkeyQry = From key In ConfigurationManager.AppSettings Where key Like "CompanyDbName*" Select key

            ''//for each company database look for PO's
            For Each KeyName In appkeyQry
                dbName = ConfigurationManager.AppSettings(KeyName)
                dbServer = ConfigurationManager.AppSettings("CompanyDbServer" & i)
                billToCompany = ConfigurationManager.AppSettings(dbName)

                dtBillTo = GetCustomer(billToCompany, partDepotDbName, partDepotDbServer)
                If dtBillTo.Rows.Count = 0 Then
                    Throw New Exception("Customer record for company database '" & dbName & "' not found in the parts depot!")
                End If
                ''//billtoCompAddr1 = dtBillTo.Rows(0)("cmp_fadd1")

                ''//get all the unprocessed, printed PO's from the current company.
                POData  = GetPoDataset(dbName, dbServer)

                If POData Is Nothing Then
                    ''// do you really want to quit here, or do you want to move to the next key? 
                    ''// Your error handling is.. inconsistent
                    Console.WriteLine("Error processing part depot: " & errMsg)
                    Exit Function
                End If

                Dim itemNum As String, qtyOrd As Double, requestDate As Date, promiseDate As Date, lineNum As String, itemPrice As Double
                Dim errNum As Integer = 0
                Dim poNum As String

                ''//use control/break style processing loop
                Dim dt As DataTable = POData.Tables(0) ''// save some typing later
                Dim dr As DataRow = dt.Rows(0)
                Dim j As Integer = 0 ''// 'i' is already in use
                While j < dt.Rows.Count   ''//for each unprocessed, printed PO in the current company

                    ''//Do setup work for next Order Number
                    Console.WriteLine("Processing PO#: " & dr("ord_no") & " in " & dbName)

                    Using wsConn As Wisys.Allsystem.ConnectionInfo = OpenWiSysConn(partDepotDbName, partDepotDbServer, True), _
                          wsPartDepotSalesOrd As New Wisys.Oe.OrderEntryTables

                        wsPartDepotSalesOrd.Connection(wsConn, errMsg)

                        With wsPartDepotSalesOrd.OrderHeader
                            .UserName = My.User.Name
                            .Ship_to_name = If(IsDBNull(dr("cmp_name")), "", dr("cmp_name"))
                            .Ship_to_addr_1 = If(IsDBNull(dr("cmp_fadd1")), "", dr("cmp_fadd1"))
                            .Ship_to_addr_2 = If(IsDBNull(dr("cmp_fadd2")), "", dr("cmp_fadd2"))
                            .Ship_to_addr_3 = If(IsDBNull(dr("cmp_fadd3")), "", dr("cmp_fadd3"))
                            .Ship_to_addr_4 = If(IsDBNull(dr("cmp_fcity")), "", dr("cmp_fcity")) & " , " & _
                                If(IsDBNull(dr("StateCode")), "", dr("StateCode"))
                            .Ship_to_country = If(IsDBNull(dr("cmp_fcounty")), "", dr("cmp_fcounty"))
                            .Oe_po_no = dr("ord_no")
                        End With

                        ''//wsPartDepotSalesOrd.OrderHeader.Status 'readonly
                        errNum = wsPartDepotSalesOrd.OrderHeader.Insert(TrxEnums.OeOrderTypeEnum.Order, "", billToCompany, "", dr("ord_dt"), errMsg)
                        If errNum <> 0 Then
                            Console.WriteLine("Error Creating OE header:" & errMsg)
                        Else
                            Console.WriteLine("Created OE#" & wsPartDepotSalesOrd.OrderHeader.Ord_no)
                        End If

                        poNum = dr("ord_no")

                        ''//Process individual lines within one order
                        While j < dt.Rows.Count AndAlso poNum = dr("ord_no")
                            ''//if error then skip to the next loop iteration until the next PO # and it gets inserted ok
                            If errNum <> 0 Then
                                lineNum = If(IsDBNull(dr("line_no")), Now(), dr("line_no"))
                                itemNum = dr("item_no").ToString
                                qtyOrd = If(IsDBNull(dr("qty_ordered")), 0, CDbl(dr("qty_ordered")))
                                requestDate = If(IsDBNull(dr("request_dt")), Now(), dr("request_dt"))
                                promiseDate = If(IsDBNull(dr("promise_dt")), Now(), dr("promise_dt"))
                                itemPrice = If(IsDBNull(dr("price")), 0, dr("price"))

                                If itemNum.Length > 0 AndAlso qtyOrd <> 0 Then
                                    CreateLine(wsPartDepotSalesOrd, itemNum, qtyOrd, 0, requestDate, requestDate, promiseDate, itemPrice)
                                    ''//mark as processed, even if above fails. any lines that fail will be added to SO in parts depot by hand.
                                    markPoLineAsProcessed(dbName, dbServer, poNum, lineNum)
                                End If
                            End If
                            j += 1
                            dr = dt.Rows(j)
                        End While
                        ''//Do cleanup work from this order
                        wsConn.CloseWisysConnection(TrxEnums.TransactionAction.Commit, errMsg)
                    End Using ''// "End Using" will dispose of wsConn and wsPartDepotSalesOrd 
                End While

                poNum = ""
                i += 1
            Next KeyName
            Console.WriteLine("DONE")

        Catch ex As Exception
            Console.WriteLine("Exception processing part depot: " & ex.Message)
        End Try ''// No need for finally section: Using statement ensures the objects were disposed
    End Function

    Private Function GetCustomer(ByVal CustomerNum As String, ByVal db As String, ByVal server As String) As DataTable
        Dim ds As New DataSet
        Using cn As New SqlClient.SqlConnection(GetConnectionString(db, server)), _
                cmd As New SqlCommand("select cmp_name,cmp_fadd1,coalesce(debnr,crdnr) as CusNum from dbo.cicmpy where ltrim(debnr) = @cusnum or ltrim(crdnr) = @cusnum", cn), _
                da As New SqlClient.SqlDataAdapter(cmd)

            cmd.Parameters.Add(New SqlClient.SqlParameter("@cusnum", CustomerNum))
            da.Fill(ds) ''// .Fill() will open the connection if needed
        End Using ''// Using statement guarantees cn, cmd, and da are disposed
        If ds.Tables.Count > 0 Then
            Return ds.Tables(0)
        End If
        Return Nothing
    End Function

    Private Function GetPoDataset(ByVal db As String, ByVal server As String) As DataSet
        Static Dim SQL As String = ConfigurationManager.AppSettings("getPoforPartsDepotSQL")

        Dim ds As New DataSet
        Using cn As New SqlClient.SqlConnection(GetConnectionString(db, server)), _
                cmd As New SqlCommand(SQL, cn), _
                da As New SqlClient.SqlDataAdapter(cmd)

            da.Fill(ds)
        End Using
        Return ds
    End Function

    Private Function GetConnectionString(ByVal db As String, ByVal server As String)
        Return String.Format("Persist Security Info=False;Integrated Security=true;Initial Catalog={0};server={1}", db, server)
    End Function

    Private Function OpenWiSysConn(ByVal dbName As String, ByVal dbServer As String, ByVal useTran As Boolean) As Wisys.Allsystem.ConnectionInfo
        Dim ci As New Wisys.Allsystem.ConnectionInfo()
        ci.Parameters(dbServer, dbName, "MacMSS")

        Dim errMsg As String = String.Empty
        If ci.OpenWisysConnection(useTran, errMsg) <> 0 Then
            Console.WriteLine("Error processing part depot: " & errMsg)
            Return Nothing
        End If
        Return ci
    End Function

    Private Function CreateLine(ByVal OEObj As Wisys.Oe.OrderEntryTables, ByVal partNum As String, ByVal qtyOrdered As Double, ByVal qtyToShip As Double, ByVal RequestDate As Date, ByVal RequestShipDate As Date, ByVal PromiseDate As Date, ByVal price As Double, ByVal PONum As String) As Boolean
        Dim OeLine As OEORDLIN
        Dim RtnErrMsg As String = ""
        Dim RtnVal As Long
        Dim RtnLineNumber As Long

        With OEObj
            ''//p_lRtnVal = .OrderHeader.Read(TrxEnums.OeOrderTypeEnum.Order, RtnOrder, True, True, True, RtnRecFound, RtnErrMsg)
            OeLine = .OrderHeader.OrderLines.Add(TrxEnums.OrderLineType.InventoryItem, partNum.ToUpper, "", qtyOrdered, qtyToShip, price, price, RequestDate, PromiseDate, RequestShipDate, True, RtnErrMsg)
            RtnVal = OeLine.Insert(RtnLineNumber, RtnErrMsg)

            If RtnVal = 0 Then Return True

            Console.WriteLine("Error creating sales order line# " & RtnLineNumber & ": " & RtnErrMsg)
            sendBadPOLineEmailtoDepot("Error creating sales order line for PO# " & PONum & " because of an error: " & RtnErrMsg)
            Return False
        End With
    End Function

    Private Function markPoLineAsProcessed(ByVal DB As String, ByVal server As String, ByVal poOrdNum As String, ByVal poLineNum As String) As Boolean
        Static Dim SQL As String = ConfigurationManager.AppSettings("markPoLineAsSendToDepotSQL")

        Using cn As New SqlClient.SqlConnection(GetConnectionString(DB, server)), _
             cmd As New SqlClient.SqlCommand(SQL, cn)

            cmd.Parameters.Add(New SqlClient.SqlParameter("@poOrdNum", poOrdNum))
            cmd.Parameters.Add(New SqlClient.SqlParameter("@poLineNum", poLineNum))

            cn.Open()
            cmd.ExecuteNonQuery()
        End Using
        Return True
    End Function

    Private Function sendBadPOLineEmailtoDepot(ByVal msgText As String) As Boolean
        Try
            If ConfigurationManager.AppSettings("EnableSentBadPOMail").ToLower <> "true" Then Return True
            Dim MailServer As String = ConfigurationManager.AppSettings("MailServer")
            Dim ToAddress As String = ConfigurationManager.AppSettings("BadPOMailTo")
            Dim FromAddress As String = ConfigurationManager.AppSettings("BadPOMailFrom")

            Dim mySmtpClient As New System.Net.Mail.SmtpClient(MailServer)
            mySmtpClient.UseDefaultCredentials = True
            mySmtpClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network

            mySmtpClient.Send(FromAddress, ToAddress, msgText, msgText)
            Return True
        Catch ex As Exception
            Console.WriteLine("Exception sending sending bad PO line e-mail to depot: " & ex.Message)
            Return False
        End Try
    End Function
End Class

特定のエラーについては、バッファを介して書き込みを行ったり、バッファをバイパスしたりすることがあるようです。または、ファイル内の各「レコード」セグメント (レコードが日付で始まり、「DONE」で終わる) がアプリの個別のインスタンスの結果である場合、いくつかのインスタンスの書き込みの結果も表示される可能性があります。同時にファイルに。サーバーとテスト環境との間の潜在的な違いの 1 つはトラフィックの量であるため、これも理にかなっています。

于 2009-02-10T15:50:05.580 に答える
1

これが1つのスレッドで実行されていることは確かですか? 一度に複数の反復が実行され、同じパイプ (stdout/console.wl) に書き込んでいるように見えます。appkeyqry の反復ごとに異なるログ (「log-{date}.txt」など) を使用して、ログをファイルに書き込んでみてください。サーバーがマルチコアで、競合状態が発生している可能性がありますか?

編集: 各 Console.Write (Console.Out.Flush) の後に stdout をフラッシュしてみてください。(私は多くのperlスクリプトを書いていますが、高速サーバーでは、各書き込み後にstdoutを常にフラッシュするように設定しない限り、出力はあなたのものと同じようにすべて混同されます).

HTH、本当に;)

于 2009-02-10T16:36:30.333 に答える