Works in debug - not live

debbieb

Member
Joined
Mar 13, 2013
Messages
8
Programming Experience
Beginner
Hi,
I'm having and issue that my code works perfectly while in debug mode, but does nothing in live. I don't receive any errors - it just doesn't insert the row into the database.

-NEVERMIND it needed to add a "Wait" function so the values could catch up.
 
Last edited:
Hi,
you are right, it doesn't seem to be working correctly. Sometimes the code works and sometimes it doesn't do anything. I had added "System.Threading.Thread.Sleep(3000)" throughout my code (playing with the times in some places, until it seemed to be working) - but it still isn't consistent and seems to be wasting time... Here is my code:
     If e.Item.OwnerTableView.Name = "DigitalInsertions" Then
            Dim fullAdNumber As String = e.Item.GetDataKeyValue("AdNumber")
            Dim Adnumber As String = Mid(fullAdNumber, 3, 7)

            Dim IS_Property_Updated As String
            Dim IS_Label_Updated As String
            Dim IS_DeliveryType_Updated As String
            Dim IS_ESOV_Updated As String
            Dim IS_StartDate_Updated As String
            Dim IS_MonthlyImpressions_Updated As String
            Dim IS_CPM_Updated As String
            Dim IS_FlatRateAmount_Updated As String
            Dim IS_YahooProgram_Updated As String
            Dim IS_YahooTarget_Updated As String
            Dim IS_GeoZones_Updated As String
            Dim IS_YahooDMATarget_Updated As String
            Dim IS_CreativeWorkOrderNum_Updated As String
            Dim IS_Subsite_Updated As String
            Dim IS_Position_Updated As String
            Dim IS_EndDate_Updated As String
            Dim IS_TotalImpressions_Updated As String
            Dim IS_TotalAmount_Updated As String
            Dim IS_ClickThruURL_Updated As String
            Dim IS_CancelIO_Updated As String
            Dim IS_BTComments_Updated As String
            Dim LastUpdatedby As String
            Dim text1 As String
            Dim text2 As String
            Dim text3 As String
            Dim text4 As String
            Dim text5 As String
            Dim text6 As String
            Dim text7 As String
            Dim text8 As String
            Dim text9 As String
            Dim text10 As String
            Dim text11 As String
            Dim text12 As String
            Dim text13 As String
            Dim text14 As String
            Dim text15 As String
            Dim text16 As String
            Dim text17 As String
            Dim text18 As String
            Dim text19 As String
            Dim text20 As String
            Dim text21 As String

            Dim LastUpdatedDateSql As String = "SELECT [dbo].[fn_MostRecentModifiedDateForThisAdDIR]('" + AdNumber + "')"
            Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("CRMConnectionString").ToString()
            Dim command As SqlCommand = Nothing
 
            command = New SqlCommand(LastUpdatedDateSql, New SqlConnection(strConnString))
            command.Connection.Open()
 
            Dim LastUpdatedDate As String = command.ExecuteScalar().ToString
 
            Dim mostrecentsavedate As DateTime = DateTime.ParseExact(LastUpdatedDate, "M/dd/yyyy h:mm:ss tt", Globalization.CultureInfo.InvariantCulture)
            Dim mysearchdate As String = mostrecentsavedate.ToString("yyyy-MM-dd HH:mm:ss")

            System.Threading.Thread.Sleep(3000)
            Dim sql2 As String = "SELECT * FROM [dbo].[fn_GetChangedRowsDIR] () where AdNumber='" + Adnumber + "' and Lastupdateddate >= '" + mysearchdate + "' and lastupdateddate< dateadd(s,3,'" + mysearchdate + "')"

            command = New SqlCommand(sql2, New SqlConnection(strConnString))
            command.Connection.Open()
            Dim reader As SqlDataReader = command.ExecuteReader()
            Try
                While reader.Read
                    IS_Property_Updated = reader.GetValue(1).ToString
                    IS_Label_Updated = reader.GetValue(2).ToString
                    IS_DeliveryType_Updated = reader.GetValue(3).ToString
                    IS_ESOV_Updated = reader.GetValue(4).ToString
                    IS_StartDate_Updated = reader.GetValue(5).ToString
                    IS_MonthlyImpressions_Updated = reader.GetValue(6).ToString
                    IS_CPM_Updated = reader.GetValue(7).ToString
                    IS_FlatRateAmount_Updated = reader.GetValue(8).ToString
                    IS_YahooProgram_Updated = reader.GetValue(9).ToString
                    IS_YahooTarget_Updated = reader.GetValue(10).ToString
                    IS_GeoZones_Updated = reader.GetValue(11).ToString
                    IS_YahooDMATarget_Updated = reader.GetValue(12).ToString
                    IS_CreativeWorkOrderNum_Updated = reader.GetValue(13).ToString
                    IS_Subsite_Updated = reader.GetValue(14).ToString
                    IS_Position_Updated = reader.GetValue(15).ToString
                    IS_EndDate_Updated = reader.GetValue(16).ToString
                    IS_TotalImpressions_Updated = reader.GetValue(17).ToString
                    IS_TotalAmount_Updated = reader.GetValue(18).ToString
                    IS_ClickThruURL_Updated = reader.GetValue(19).ToString
                    IS_CancelIO_Updated = reader.GetValue(20).ToString
                    IS_BTComments_Updated = reader.GetValue(21).ToString
                    LastUpdatedby = reader.GetValue(54).ToString
                    System.Threading.Thread.Sleep(2000)
                    If IS_Property_Updated = "True" Then
                        text1 = "Property was updated, "
                    Else
                        text1 = ""
                    End If
                    If IS_Label_Updated = "True" Then
                        text2 = "Label was updated, "
                    Else
                        text2 = ""
                    End If
                    If IS_DeliveryType_Updated = "True" Then
                        text3 = "DeliveryType was updated, "
                    Else
                        text3 = ""
                    End If
                    If IS_ESOV_Updated = "True" Then
                        text4 = "ESOV was updated, "
                    Else
                        text4 = ""
                    End If
                    If IS_StartDate_Updated = "True" Then
                        text5 = "StartDate was updated, "
                    Else
                        text5 = ""
                    End If
                    If IS_MonthlyImpressions_Updated = "True" Then
                        text6 = "MonthlyImpressions was updated, "
                    Else
                        text6 = ""
                    End If
                    If IS_CPM_Updated = "True" Then
                        text7 = "CPM was updated, "
                    Else
                        text7 = ""
                    End If
                    If IS_FlatRateAmount_Updated = "True" Then
                        text8 = "FlatRateAmount was updated, "
                    Else
                        text8 = ""
                    End If
                    If IS_YahooProgram_Updated = "True" Then
                        text9 = "YahooProgram was updated, "
                    Else
                        text9 = ""
                    End If
                    If IS_YahooTarget_Updated = "True" Then
                        text10 = "YahooTarget was updated, "
                    Else
                        text10 = ""
                    End If
                    If IS_GeoZones_Updated = "True" Then
                        text11 = "GeoZones was updated, "
                    Else
                        text11 = ""
                    End If
                    If IS_YahooDMATarget_Updated = "True" Then
                        text12 = "YahooDMATarget was updated, "
                    Else
                        text12 = ""
                    End If
                    If IS_CreativeWorkOrderNum_Updated = "True" Then
                        text13 = "CreativeWorkOrderNum was updated, "
                    Else
                        text13 = ""
                    End If
                    If IS_Subsite_Updated = "True" Then
                        text14 = "Subsite was updated, "
                    Else
                        text14 = ""
                    End If
                    If IS_Position_Updated = "True" Then
                        text15 = "Position was updated, "
                    Else
                        text15 = ""
                    End If
                    If IS_EndDate_Updated = "True" Then
                        text16 = "EndDate was updated, "
                    Else
                        text16 = ""
                    End If
                    If IS_TotalImpressions_Updated = "True" Then
                        text17 = "TotalImpressions was updated, "
                    Else
                        text17 = ""
                    End If
                    If IS_TotalAmount_Updated = "True" Then
                        text18 = "TotalAmount was updated, "
                    Else
                        text18 = ""
                    End If
                    If IS_ClickThruURL_Updated = "True" Then
                        text19 = "ClickThruURL was updated, "
                    Else
                        text19 = ""
                    End If
                    If IS_CancelIO_Updated = "True" Then
                        text20 = "CancelIO was updated, "
                    Else
                        text20 = ""
                    End If
                    If IS_BTComments_Updated = "True" Then
                        text21 = "BTComments was updated, "
                    Else
                        text21 = ""
                    End If
                    Dim mychange As String = "" + text1 & text2 & text3 & text4 & text5 & text6 & text7 & text8 & text9 & text10 & text11 & text12 & text13 & text14 & text15 & text16 & text17 & text18 & text19 & text20 & text21 + "."
                    System.Threading.Thread.Sleep(5000)
                    Dim Sql3 As String = "INSERT INTO [dbo].[DigitalInsertionOrderHistory] " &
            "([LastUpdatedby]" &
            ",[LastUpdatedDate]" &
            ",[DIORecID]" &
            ",[Changes])" &
            " VALUES (" &
            "'" & LastUpdatedby & "'" &
            ",'" & mysearchdate & "'" &
            ",'" & Adnumber & "'" &
            ",'" & mychange & "')"
                    System.Threading.Thread.Sleep(2000)
                    Dim strConnString2 As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("CRMConnectionString").ToString()
                    Dim sqlConn As SqlConnection = Nothing

                    sqlConn = New SqlConnection(strConnString2)
                    Dim sqlcmd As New SqlCommand()
                    sqlConn.Open()
                    sqlcmd.Connection = sqlConn
                    System.Threading.Thread.Sleep(1000)
                    sqlcmd.CommandText = Sql3
                    sqlcmd.ExecuteNonQuery()
                    sqlConn.Close()
                End While
            Catch ex As Exception
            Finally
                command.Connection.Close()
            End Try
        End If

Any help on a better way to do this is GREATLY appreciated.

Thanks,
Debbie



Exactly how did you implement this "Wait" function and exactly why? It sounds very dodgy to me and is almost certainly not the best way to solve your problem.

Forgot to add that i'm working in Visual Basic 2012 on an asp.net page (if it helps any).
 
Last edited by a moderator:
Back
Top