VB.NET - Exception has been thrown by the target

Asked By Drexler Kan
28-Dec-05 09:11 PM
Hello everyone,I'm migrating the VB Engine to VB.NET. I manage to run the function only in the first time,it will occur this error>>"Exception has been thrown by the target of an invocation" when it start with the second time running. This Engine is set to run by time intervals. Anyone can help me to solve the problem? The code are as follow:

Imports System.Data.SqlClient
Imports System.Data.DataException
Imports System.DateTime
Public Class First
    Inherits System.Windows.Forms.Form
    Dim strSQL, code, media, time_stamp2, itemcode, Status, Sms_Type, ShortCode, AppId, Message, content As String
    Dim Id, phoneno, receiverno, Transaction_Id, Source_Mobtel, Maxis_Msg_Id, Digi_Msg_Id As String
    Dim Digi_Price, Maxis_Price, Celcom_Price, Celcom_Serviceid, TmTouch_Price, TmTouch_Serviceid, Maxis_Serviceid As String
    Dim datetimestamp As Date
    Dim RawCode, Allcode, Telco, BillFlag, item_code As Integer
    Dim M(10) As String
    Dim P(10) As String
    Dim Dedi_Num As String
    Dim realcode As String
    Dim Valentine_Charge As Boolean
    Dim Free_RT_member_Charge As Boolean
    Dim Renewal_Date As String
    Dim ThisWeekKeyword As String
    Dim Obconn = New SqlConnection("server=(local);database=;")
    Dim Obconn1 = New SqlConnection("server=(local);database=;")
    Dim Obread As SqlDataReader
    Dim Obread1 As SqlDataReader
    Dim Obcomm As SqlCommand
    Dim Obcomm1 As SqlCommand
  
    Private Sub First_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Dim temp As String
        Dim Obcomm As New SqlCommand
        ThisWeekKeyword = "yz"
        'ThisWeekKeyword = "dp"
        Try
            Obcomm = New SqlCommand("select top 1 * from TT_List where type=1 order by time_rcv desc", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Obread.Read Then
                For i = 1 To 10
                    temp = "S" & i
                    M(i) = temp
                Next
            Else
                MessageBox.Show("Error from First_Load")
            End If
            Obconn.close()
        
            Obcomm = New SqlCommand("select top 1 * from TT_List where type=2 order by time_rcv desc", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Obread.Read Then
                For i = 1 To 10
                    temp = "S" & i
                    P(i) = temp
                Next
            Else
                MessageBox.Show("Error from First_Load")
            End If
            Obconn.Close()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            If Microsoft.VisualBasic.DatePart("h", Microsoft.VisualBasic.Now) < 8 Then
                Timer1.Interval = 60000
                'MessageBox.Show("Now running Slow Mode")
            Else
                Timer1.Interval = 5000
                'MessageBox.Show("Now running Fast Mode")
            End If
        Catch ex As Exception
        End Try
        Call Distribution()
        Call Check_Wait()
    End Sub
    Private Sub Distribution()
        Dedi_Num = "0"
        code = ""
        realcode = ""
        receiverno = ""
        content = ""
        Id = ""
        Dim i As Integer
        Dim Temp_counter As Integer
        Dim The_real As String
        Temp_counter = 0
        Obcomm = New SqlCommand("select top 1 * from TT_MO where read_flag =0  order by id", Obconn)
        Obconn.Open()
        Obread = Obcomm.ExecuteReader
        If Obread.Read Then
            Id = Obread.GetValue(0)
            AppId = Obread.GetValue(1)
            Transaction_Id = Obread.GetValue(3)
            ShortCode = Obread.GetValue(4)
            Source_Mobtel = Obread.GetValue(5)
            Message = Obread.GetValue(6)
            Telco = Obread.GetValue(10)
            Obconn.Close()
            'Check to ensure it only get numeric 0-9, character A-Z and a-z #############
            For i = 1 To Len(Message)
                If (Asc(Mid$(Message, i, 1)) > 47 And Asc(Mid$(Message, i, 1)) < 58 Or (Asc(Mid$(Message, i, 1)) > 64 And Asc(Mid$(Message, i, 1)) < 91) Or (Asc(Mid$(Message, i, 1)) > 96 And Asc(Mid$(Message, i, 1)) < 173)) Then
                    content = content & Mid$(Message, i, 1)
                End If
            Next i
            TextBox1.Text = content
            'Stop Subscription
            If LCase(content) Like "ttoff*" Or LCase(content) Like "ttstop*" Or LCase(content) Like "ttbatal*" Or LCase(content) Like "*batal*" Or LCase(content) Like "*stop*" Or LCase(content) Like "*off*" Then
                'MessageBox.Show("I feel like people asking me to stop")
                Call Send_TT_Stop()
                Exit Sub
                'Download
            ElseIf LCase(content) Like "d*" Or LCase(content) Like "p*" Or LCase(content) Like "y*" Or LCase(content) Like "z*" Then
                'MessageBox.Show("Now we are running download ")
                code = Check_SP_code(content)
                Call Process()
                'Send enrol command
            ElseIf LCase(content) Like "tton*" Or LCase(content) Like "ontt*" Then
                Obcomm = New SqlCommand("select * from TT_member where mobile_no like '" & Source_Mobtel & "'", Obconn)
                Obconn.Open()
                Obread = Obcomm.ExecuteReader()
                'MessageBox.Show("I'm jumping inside the TTON")
                If Not Obread.Read Then
                    Obconn.Close()
                    Call New_Member()
                Else
                    If Obread.GetValue(3) = 0 Then
                        Obconn.Close()
                        Call New_Member()
                    Else
                        Obconn.Close()
                        Call Already_Member()
                    End If
                End If
                'set profile
            ElseIf LCase(content) Like "ttp" Or LCase(content) Like "ttm" Then
                Obcomm = New SqlCommand("select * from TT_member where mobile_no like '" & Source_Mobtel & "'", Obconn)
                Obconn.Open()
                Obread = Obcomm.ExecuteReader()
                'MessageBox.Show("I'm running inside setting user profile")
                If Not Obread.Read Then
                    Obconn.close()
                    Call New_Member()
                Else
                    Obconn.close()
                    Call Set_Profile()
                End If
            Else
                Call Handle_Incorrect_Code()
            End If
        Else
            'MessageBox.Show("Finish checking all the TT_MO")
            Dim response As MsgBoxResult
            response = MsgBox("Stop the Engine ?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo)
            If response = MsgBoxResult.Yes Then
                End
            End If
        End If
    End Sub
    Private Sub Already_Member()
        'Change Price to 20 cents
        Maxis_Price = "000"
        Maxis_Serviceid = "905"
        Digi_Price = "u0shABRAVhmruYG9Y9kLnw%3D%3D"
        Celcom_Price = "0030"
        Celcom_Serviceid = "007"
        TmTouch_Price = "0030"
        TmTouch_Serviceid = "1"
        BillFlag = 0
        Maxis_Msg_Id = Transaction_Id
        Digi_Msg_Id = Transaction_Id
        Try
            If Telco = 2 Then
                Call Send_MT_Msg("Free Msg.You are an existing TopTenClub member.Pls choose your profile(TTM-Monotones or TTP-Polytones).Pls type TTM or TTP & send to 32132.HelpLine:03-78805708.Tq")
            Else
                Call Send_MT_Msg("This Msg RM0.30.You are an existing TopTenClub member.Pls choose your profile(TTM-Monotones or TTP-Polytones).Pls type TTM or TTP & send to 32132.HelpLine:03-78805708.Tq")
            End If
            Call close_record()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Send_TT_Stop()
        Dim SysTime
        SysTime = DateTime.Now
        Sms_Type = "Send_TT_Stop"
        Try
            Obcomm = New SqlCommand("select * from TT_member where mobile_no like '" & Source_Mobtel & "' and status=1", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            
            'Change Price to 20 cents
            Maxis_Price = "000"
            Maxis_Serviceid = "905"
            Digi_Price = "u0shABRAVhmruYG9Y9kLnw%3D%3D"
            Celcom_Price = "0030"
            Celcom_Serviceid = "007"
            TmTouch_Price = "0030"
            TmTouch_Serviceid = "1"
            BillFlag = 0
            Maxis_Msg_Id = Transaction_Id
            Digi_Msg_Id = Transaction_Id

            If Obread.Read Then
                'MessageBox.Show("Ok,got your member here and I will stop the member")
                Obconn.Close()
                Obcomm = New SqlCommand("Update TT_Member set status = '0' ,  Time_Unregister='" & DateTime.Now & "'where Mobile_No = '" & Source_Mobtel & "'", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.close()
                If Telco = 2 Then
                    Call Send_MT_Msg("Free Msg. Your subscription to TT has been terminated. Thank you for your patronage. HelpLine:03-78805708.")
                Else
                    Call Send_MT_Msg("This msg-RM0.30. Your subscription to TT has been terminated. Thank you for your patronage. HelpLine:03-78805708.")
                End If
            Else
                Obconn.Close()
                If Telco = 2 Then
                    Call Send_MT_Msg("Free Msg. You are not a TT Subscriber & will not receive any TT. To subscribe TT, send ON TT to 32132. HelpLine:03-78805708.")
                Else
                    Call Send_MT_Msg("This msg-RM0.30. You are not a TT Subscriber & will not receive any TT. To subscribe TT, send ON TT to 32132. HelpLine:03-78805708.")
                End If
            End If
        Catch ex As Exception
        End Try
        Call close_record()
    End Sub
    Private Sub New_Member()
        Try
            Dim SysTime
            SysTime = DateTime.Now
            'Charge RM2
            Maxis_Price = "200"
            Maxis_Serviceid = "905"
            Digi_Price = "HoiA6mdL1%2F2ruYG9Y9kLnw%3D%3D"
            Celcom_Price = "0200"
            Celcom_Serviceid = "001"
            TmTouch_Price = "0200"
            TmTouch_Serviceid = "1"
            Sms_Type = "Send_TT_MT_New_Member"
            BillFlag = 1
            Maxis_Msg_Id = Transaction_Id
            Digi_Msg_Id = Transaction_Id
            Call Get_Renewal_Date()
            Call Send_MT_Msg("This Msg RM2.Successful Registration Fee:RM2/week.Price:RM1.50/download. Renewal " & Renewal_Date & " To Cancel send STOP TT to 32132.")
            'No charge
            Maxis_Price = "000"
            Maxis_Serviceid = "905"
            Digi_Price = "zf%2B6na155gqruYG9Y9kLnw%3D%3D"
            Celcom_Price = "0000"
            Celcom_Serviceid = "000"
            TmTouch_Price = "0000"
            TmTouch_Serviceid = "1"
            Sms_Type = "Send_TT_MT_Set_Profile"
            BillFlag = 0
            Maxis_Msg_Id = 0
            Digi_Msg_Id = 0

            Call Send_MT_Msg("Free Msg. TopTenClub member.Pls choose your profile(TTM-Monotones or TTP-Polytones).Pls type TTM or TTP & send to 32132.HelpLine:03-78805708.Tq")
            Obcomm = New SqlCommand("select * from TT_member where mobile_no = '" & Source_Mobtel & "'", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Not Obread.Read Then
                Obconn.close()
                Obcomm1 = New SqlCommand("insert into TT_member(mobile_no,time_rcv,status)values('" & Source_Mobtel & "','" & SysTime & "','1')", Obconn1)
                Obconn1.Open()
                Obcomm1.ExecuteNonQuery()
                Obconn1.Close()
            Else
                Obconn.close()
                Obcomm1 = New SqlCommand("update TT_member set status = '1' where mobile_no ='" & Source_Mobtel & "'", Obconn1)
                Obconn1.Open()
                Obcomm1.ExecuteNonQuery()
                Obconn1.Close()
            End If
            Obconn.Close()
            Call close_record()
        Catch ex As Exception
        End Try
    End Sub
    Private Function Check_SP_code(ByVal SP_Code As String)
        Dim the_number As String
        Dim the_code, tempcode As String
        the_number = ""
        tempcode = ""
        Try
            If Len(SP_Code) = 12 Or Len(SP_Code) = 2 Then
               
                'Check Special_Code database
                Obcomm = New SqlCommand("SELECT * FROM Special_Code_TT WHERE Special_Code='" & Mid$(SP_Code, 1, 2) & "'", Obconn)
            ElseIf Len(SP_Code) = 13 Or Len(SP_Code) = 3 Then
               
                'Check Special_Code database
                Obcomm = New SqlCommand("SELECT * FROM Special_Code_TT WHERE Special_Code='" & Mid$(SP_Code, 1, 3) & "'", Obconn)
            Else
                
                'Check Special_Code database
                Obcomm = New SqlCommand("SELECT * FROM Special_Code_TT WHERE Special_Code='" & Mid$(SP_Code, 1, 2) & "'", Obconn)
            End If
            Obconn.Open()
            Obread = Obcomm.ExecuteReader()
            'Set the Media Code
            If Obread.Read Then
                tempcode = Obread.GetValue(2)
                Obconn.Close()
                the_code = "95" & tempcode
            Else
                Obconn.Close()
                the_code = ""
            End If
            Check_SP_code = the_code
        Catch ex As Exception
        End Try
    End Function
    Private Sub Handle_Incorrect_Code()
        Status = "Error"
        Sms_Type = "Send_TT_MT_Error_Code"
        'Change Price to 20 cents
        Maxis_Price = "000"
        Maxis_Serviceid = "905"
        Digi_Price = "u0shABRAVhmruYG9Y9kLnw%3D%3D"
        Celcom_Price = "0030"
        Celcom_Serviceid = "007"
        TmTouch_Price = "0030"
        TmTouch_Serviceid = "1"
        BillFlag = 0
        Maxis_Msg_Id = Transaction_Id
        Digi_Msg_Id = Transaction_Id
        Try
            If Telco = 2 Then
                Call Send_MT_Msg("Free msg. For more info, pls call our customer service helpline at 03-78805708.Office hours:Mon-Fri,9am-6pm. TQ.")
            Else
                Call Send_MT_Msg("This Msg-RM0.30. For more info, pls call our customer service helpline at 03-78805708.Office hours:Mon-Fri,9am-6pm. TQ.")
            End If
            MessageBox.Show("There is error on the message sent in")
        Catch ex As Exception
        End Try
        Call store_record()
    End Sub
    Private Sub Get_Renewal_Date()
        Dim SysTime
        SysTime = DateTime.Now
        Dim Renewal_Date_dd As String
        Dim Renewal_Date_mm As String
        Dim Renewal_Date_yy As String
        Try
            Renewal_Date = SysTime
            If WeekdayName(Weekday(Renewal_Date)) = "Monday" Then
                Renewal_Date = DateAdd("d", 2, Renewal_Date)
            ElseIf WeekdayName(Weekday(Renewal_Date)) = "Tuesday" Then
                Renewal_Date = DateAdd("d", 1, Renewal_Date)
            ElseIf WeekdayName(Weekday(Renewal_Date)) = "Wednesday" Then
                Renewal_Date = DateAdd("d", 7, Renewal_Date)
            ElseIf WeekdayName(Weekday(Renewal_Date)) = "Thursday" Then
                Renewal_Date = DateAdd("d", 6, Renewal_Date)
            ElseIf WeekdayName(Weekday(Renewal_Date)) = "Friday" Then
                Renewal_Date = DateAdd("d", 5, Renewal_Date)
            ElseIf WeekdayName(Weekday(Renewal_Date)) = "Saturday" Then
                Renewal_Date = DateAdd("d", 4, Renewal_Date)
            ElseIf WeekdayName(Weekday(Renewal_Date)) = "Sunday" Then
                Renewal_Date = DateAdd("d", 3, Renewal_Date)
            End If
            Renewal_Date_dd = DatePart("d", Renewal_Date)
            Renewal_Date_mm = DatePart("m", Renewal_Date)
            Renewal_Date_yy = DatePart("yyyy", Renewal_Date)
            Renewal_Date = Renewal_Date_dd & "/" & Renewal_Date_mm & "/" & Mid(Renewal_Date_yy, 3, 2)
        Catch ex As Exception
        End Try
    End Sub
    Private Sub store_record()
        Dim SysTime
        SysTime = DateTime.Now
        Try
            Obcomm = New SqlCommand("SELECT top 1 * FROM TT_archive", Obconn)
            If Sms_Type = "Send_TT_MT_Stop" Then
                Obcomm = New SqlCommand("Insert into TT_archive(messageid,mobile_no,receiver_no,time_rcv,status,telco)values('" & Transaction_Id & "','" & Source_Mobtel & "','OFF','" & SysTime & "','" & Status & "','" & Telco & "')", Obconn)
            Else
                Obcomm = New SqlCommand("Insert into TT_archive(messageid,mobile_no,receiver_no,time_rcv,Product_code,item_code,media_code,status,telco)values('" & Transaction_Id & "','" & Source_Mobtel & "','" & receiverno & "','" & SysTime & "','" & realcode & "','" & itemcode & "','" & media & "','" & Status & "','" & Telco & "')", Obconn)
            End If
            Obconn.Open()
            Obcomm.ExecuteNonQuery()
            Obconn.Close()
        Catch ex As Exception
        End Try
    End Sub
    Function Send_MT_Msg(ByVal msg As String)
        Dim str, strurl, session_id As String
        Dim MT_Msg, Encode_MT_Msg As String
        Dim SysTime
        SysTime = DateTime.Now
        Try
            If Len(receiverno) = 0 Then
                Obcomm = New SqlCommand("select * from TT_MO where read_flag =0 and Id ='" & Id & "'", Obconn)
                Obconn.Open()
                Obread = Obcomm.ExecuteReader
                If Obread.Read Then
                    receiverno = Obread.GetValue(5)
                Else
                    MessageBox.Show("Error in the Send_MT_Msg")
                End If
                Obconn.Close()
            End If
            MT_Msg = msg
            Encode_MT_Msg = URLencode(MT_Msg)
            If Mid$(receiverno, 3, 1) = 1 Then
                Call get_time()
                Obcomm = New SqlCommand("Insert into Maxis_MT(AppId,Trackid,SenderNumber,DestinationAddress,OriginatingAddress,Messagecount,Time_stamp,Scheduleflag,Scheduletime,Billflag,Serviceid,Price,M1,Read_flag,Use_Flash,Service,Time_rcv,Sms_type)values('" & AppId & "','" & Maxis_Msg_Id & "','" & receiverno & "','" & receiverno & "','" & ShortCode & "','1','" & time_stamp2 & "','0','0','" & BillFlag & "','" & Maxis_Serviceid & "','" & Maxis_Price & "','" & MT_Msg & "','0','0','TT','" & SysTime & "','" & Sms_Type & "')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.close()
            ElseIf Mid$(receiverno, 3, 1) = 3 Then
                Obcomm = New SqlCommand("Insert into TmTouch_MT(Short_code,Price_code,Telco,Sender,Service_id,Destination,Keyword,Transaction_id,Msg_id,Msg_count,Type,Udh,Detail,Time_rcv,Err_msg,SMS_Type,Read_flag)values('" & ShortCode & "','" & TmTouch_Price & "','013','" & receiverno & "','" & TmTouch_Serviceid & "','" & receiverno & "','TT','0','1','1','1','0','" & Encode_MT_Msg & "','" & SysTime & "','1','" & Sms_Type & "','0')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            ElseIf Mid$(receiverno, 3, 1) = 9 Then
                Obcomm = New SqlCommand("Insert into Celcom_MT(Short_code,Price_code,Telco,Sender,Service_id,Destination,Keyword,Transaction_id,Msg_id,Msg_count,Type,Udh,Detail,Time_rcv,Err_msg,Sms_type,Read_flag)values('" & ShortCode & "','" & Celcom_Price & "','019','" & receiverno & "','" & Celcom_Serviceid & "','" & receiverno & "','TT','0','1','1','1','0','" & Encode_MT_Msg & "','" & SysTime & "','1','" & Sms_Type & "','0')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            ElseIf Mid$(receiverno, 3, 1) = 6 Then
                Obcomm = New SqlCommand("Insert into DiGi_MT(cpa_cp_id,cpa_cp_response_url,cpa_short_code,cpa_keyword,cpa_service_id,cpa_transaction_id,cpa_source_mobtel,cpa_destination_mobtel,cpa_charge_party,cpa_delivery_channel,cpa_prepaid_price_code,cpa_postpaid_price_code,cpa_status,cpa_error_code,cpa_content_sequence,cpa_max_content,cpa_content,time_rcv,type,read_flag)values('204','http%3A%2F%2F192.168.11.10%2FDiGi%2Fmt_response.asp','32132','TT','CPA_QDELUXE_32132','" & Digi_Msg_Id & "','" & receiverno & "','" & receiverno & "','S','SMS','" & Digi_Price & "','" & Digi_Price & "','1','1','1','1','" & Encode_MT_Msg & "','" & SysTime & "','" & Sms_Type & "','0')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            End If
        Catch ex As Exception
        End Try
    End Function
    Private Sub Process()
        Try
            If Len(code) = 6 Then
                'MessageBox.Show("I have 6 numbers")
                realcode = Microsoft.VisualBasic.Right$(code, 4)
                media = Microsoft.VisualBasic.Left(code, 4)
            ElseIf Len(code) = 7 Then
                'MessageBox.Show("I have 7 numbers")
                realcode = Microsoft.VisualBasic.Right$(code, 5)
                media = Microsoft.VisualBasic.Left(code, 2)
            ElseIf Len(code) = 8 Then
                'MessageBox.Show("I have 8 numbers")
                realcode = Microsoft.VisualBasic.Right$(code, 4)
                media = Microsoft.VisualBasic.Left(code, 4)
            Else
                realcode = code
            End If
            If Len(realcode) = 0 Then
                Call Handle_Incorrect_Code()
                Exit Sub
            End If
            If Len(realcode) <> 5 Then
                'Item Code correction mechanism
                If Mid(realcode, 1, 1) = 3 Then
                    itemcode = 2
                ElseIf Mid(realcode, 1, 1) = 5 Or Mid(realcode, 1, 1) = 7 Then
                    itemcode = 4
                Else
                    itemcode = 1
                End If
            ElseIf Len(realcode) = 5 Then
                item_code = 5
                itemcode = 5
            End If
            If Len(realcode) > 8 Then
                Call Handle_Incorrect_Code()
                Exit Sub
            End If
            If itemcode = 1 Then 'Send RT
                Obcomm = New SqlCommand("SELECT * FROM Rt_Code WHERE Code='" & realcode & "'", Obconn)
                Obcomm1 = New SqlCommand("SELECT * FROM RT_Hex_Code WHERE Code='" & realcode & "'", Obconn1)
            ElseIf itemcode = 2 Or itemcode = 3 Then  'Send Logo
                Obcomm = New SqlCommand("SELECT * FROM Pic_Code WHERE Code='" & realcode & "'", Obconn)
                Obcomm1 = New SqlCommand("SELECT * FROM Logo_Hex_Code WHERE Code='" & realcode & "'", Obconn1)

            ElseIf itemcode = 4 Then    'Send Pic Msg
                Obcomm = New SqlCommand("SELECT * FROM Pic_Code WHERE Code='" & realcode & "'", Obconn)
                Obcomm1 = New SqlCommand("SELECT * FROM pic_Hex_Code WHERE Code='" & realcode & "'", Obconn1)

            ElseIf itemcode = 5 Then   'Send Poly/Wallpaper
                If Microsoft.VisualBasic.Left(realcode, 1) = 1 Then
                    Obcomm = New SqlCommand("SELECT * FROM Poly_Code WHERE Cool_Code='" & realcode & "'", Obconn)
                Else
                    Obcomm = New SqlCommand("SELECT * FROM ColourPic_Code WHERE Cool_Code='" & realcode & "'", Obconn)
                End If
                'Run and exit this sub
                Obconn.Open()
                Obread = Obcomm.ExecuteReader
                If Obread.Read Then
                    Obconn.close()
                    'MessageBox.Show("I'm going to Send 2 Push POLY now")
                    Call send_2_push_poly()
                    Exit Sub
                End If
                Obconn.Close()
            Else
                Call Handle_Incorrect_Code()
                Exit Sub
            End If
            Obconn.Open()
            Obread = Obcomm.ExecuteReader()
            If Obread.Read Then
                Obconn.Close()
                Obconn1.Open()
                Obread1 = Obcomm1.ExecuteReader()
                If Obread1.Read Then
                    Obconn1.Close()
                    Call send_2_push()
                    Exit Sub
                End If
            Else
                Call Handle_Incorrect_Code()
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private Sub send_2_push_poly()
        Try
            Dim polyid, tempstr, tempstr2, tempstr3, polytype, polyname, polymsg1, polymsg2 As String
            Dim hexcode, str, strurl, receiverno, send_content, send_content1, send_content2, send_content3, session_id As String
            Dim i, redeem_B4 As Integer
            Dim SysTime
            SysTime = DateTime.Now
            receiverno = Source_Mobtel
            Obcomm = New SqlCommand("Select * from TT_Member where mobile_no like '" & Source_Mobtel & "'", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Obread.Read Then
                redeem_B4 = Obread.GetValue(5)
                Obconn.Close()
                Obcomm = New SqlCommand("Update TT_Member set free_redeem = '1',status = '1' where mobile_no like '" & Source_Mobtel & "'", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            Else
                'Send Error Msg to non member
                Call Handle_Error_Msg()
                Call close_record()
                Exit Sub
            End If
            tempstr = ""
            tempstr2 = ""
            tempstr3 = ""
            polymsg1 = ""
            polymsg2 = ""
            If redeem_B4 = 1 Then
                'Change Price to Primier Price
                'Charge 150 cent
                Maxis_Price = "150"
                Maxis_Serviceid = "905"
                Digi_Price = "QlaLENu4bBuruYG9Y9kLnw%3D%3D"
                Celcom_Price = "0150"
                Celcom_Serviceid = "050"
                TmTouch_Price = "0150"
                TmTouch_Serviceid = "1"
                BillFlag = 1
                Maxis_Msg_Id = Transaction_Id
                Digi_Msg_Id = Transaction_Id
            Else
                'No Charge
                Maxis_Price = "000"
                Maxis_Serviceid = "905"
                Digi_Price = "zf%2B6na155gqruYG9Y9kLnw%3D%3D"
                Celcom_Price = "0000"
                Celcom_Serviceid = "000"
                TmTouch_Price = "0000"
                TmTouch_Serviceid = "0"
                BillFlag = 0
                Maxis_Msg_Id = 0
                Digi_Msg_Id = 0
            End If
            If Mid(realcode, 1, 1) = 1 Then
                Obcomm = New SqlCommand("SELECT * FROM Poly_Code WHERE Cool_Code='" & realcode & "'", Obconn)
                Obconn.Open()
                Obread = Obcomm.ExecuteReader
                If Obread.Read Then
                    polyname = Obread.GetValue(1)
                Else
                    MessageBox.Show("No polyname found found")
                End If
                Obconn.Close()
                Sms_Type = "Send_TT_Poly"
            Else
                Obcomm = New SqlCommand("SELECT * FROM ColourPic_Code WHERE Cool_Code='" & realcode & "'", Obconn)
                Obconn.Open()
                Obread = Obcomm.ExecuteReader
                polyname = Obread.GetValue(1)
                Obconn.Close()
                Sms_Type = "Send_TT_ColorPic"
            End If
            Obcomm = New SqlCommand("SELECT top 1 * from poly_trans order by id desc", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader()
            If Obread.Read Then
                polyid = Obread.GetValue(1)
                'MessageBox.Show("Testing and found running  polyid>>" & polyid & "<<")
            Else
                MessageBox.Show("No record found at poly_trans table")
            End If
            Obconn.Close()
            polyid = polyid + 1
            For i = 1 To Len(polyid)
                tempstr = tempstr & Hex(Asc(Mid(polyid, i, 1)))
            Next i
            'MessageBox.Show("This is the polyid>" & tempstr & "<<")
            For i = 1 To Len(polyname)
                tempstr2 = tempstr2 & Hex(Asc(Mid(polyname, i, 1)))
            Next i
            'MessageBox.Show("This is the polyname>>" & tempstr2 & "<<")
            For i = 1 To Len(receiverno)
                tempstr3 = tempstr3 & Hex(Asc(Mid(receiverno, i, 1)))
            Next i
            'MessageBox.Show("This is the receiverno>>" & tempstr3 & "<<")
            If Microsoft.VisualBasic.Mid$(receiverno, 3, 1) = 1 Then
                'MessageBox.Show("I'm running inside 012 or 017 now")
                '##             www.planetunes.com/poly.....
                polymsg1 = "0605040B8423F0090601AE02056A0045C60D03706C616E6574756E65732E636F6D2F706F6C792F3F6D6F62696C656E6F3D" & tempstr3 & "2669643D" & tempstr
                '##                         Gaya Club
                polymsg2 = polymsg1 & "000103506C616E6574756E6573204D6F62696C65202D20" & tempstr2 & "000101"
                Call get_time()
                'Add record into poly_trans table
                Obcomm = New SqlCommand("insert into poly_trans(trans_id,code,mobile_no,telco,time_rcv)values('" & polyid & "','" & realcode & "','" & receiverno & "','012','" & SysTime & "')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                'MessageBox.Show("I finish insert into polytrans table")
                Obconn.Close()
                Obcomm = New SqlCommand("Insert into Maxis_MT(Appid,Trackid,SenderNumber,DestinationAddress,OriginatingAddress,Messagecount,time_stamp,scheduleflag,scheduletime,billflag,serviceid,price,use_flash,m1,read_flag,service,time_rcv,sms_type,product_code,media_code,item_code)values('3085','" & Maxis_Msg_Id & "','" & Source_Mobtel & "','" & receiverno & "','32132','1','" & time_stamp2 & "','0','0','" & BillFlag & "','" & Maxis_Serviceid & "','" & Maxis_Price & "','0','" & polymsg2 & "','0','TT','" & SysTime & "','Send_RT_Push','" & realcode & "','" & media & "','5')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                'MessageBox.Show("Finish insert into MaxisMT")
                Obconn.Close()
            ElseIf Mid$(receiverno, 3, 1) = 6 Then
                '##             www.planetunes.com/poly.....
                polymsg1 = "0605040B8423F0090601AE02056A0045C60D03706C616E6574756E65732E636F6D2F706F6C792F3F6D6F62696C656E6F3D" & tempstr3 & "2669643D" & tempstr
                '##                         Gaya Club
                polymsg2 = polymsg1 & "000103506C616E6574756E6573204D6F62696C65202D20" & tempstr2 & "000101"
                'Add record into poly_trans table
                Obcomm = New SqlCommand("insert into poly_trans(trans_id,code,mobile_no,telco,time_rcv)values('" & polyid & "','" & realcode & "','" & receiverno & "','016','" & SysTime & "')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
                send_content = "0B0504158100000003010101" & hexcode
                Obcomm = New SqlCommand("insert into Digi_MT(cpa_cp_id,cpa_cp_response_url,cpa_short_code,cpa_keyword,cpa_transaction_id,cpa_source_mobtel,cpa_destination_mobtel,cpa_charge_party,cpa_delivery_channel,cpa_prepaid_price_code,cpa_postpaid_price_code,cpa_status,cpa_error_code,cpa_content_sequence,cpa_max_content,cpa_content,cpa_ucp_message_type,product_code,media_code,item_code,time_rcv,type,read_flag)values('204','http%3A%2F%2F192.168.11.10%2FDiGi%2Fmt_response.asp','32132','TT','" & Digi_Msg_Id & "','" & Source_Mobtel & "','" & receiverno & "','S','SMS','" & Digi_Price & "','" & Digi_Price & "','1','1','1','1','" & polymsg2 & "','4','" & realcode & "','" & media & "','5','" & SysTime & "','" & Sms_Type & "','0')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            ElseIf Mid$(receiverno, 3, 1) = 9 Then
                Obcomm = New SqlCommand("insert into poly_trans(trans_id,code,mobile_no,telco,time_rcv)values('" & polyid & "','" & realcode & "','" & receiverno & "','019','" & SysTime & "')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
                '##             www.planetunes.com/poly.....
                polymsg1 = "090601AE02056A0045C60D03706C616E6574756E65732E636F6D2F706F6C792F3F6D6F62696C656E6F3D" & tempstr3 & "2669643D" & tempstr
                '##                         Gaya Club
                polymsg2 = polymsg1 & "000103506C616E6574756E6573204D6F62696C65202D20" & tempstr2 & "000101"
                Obcomm = New SqlCommand("Insert into Celcom_MT (Short_Code,Price_Code,Telco,Sender,Service_id,Destination,Keyword,Transaction_id,Msg_id,Msg_count,type,udh,detail,time_rcv,product_code,media_code,item_code,err_msg,sms_type,read_flag)values('" & ShortCode & "','" & Celcom_Price & "','019','" & receiverno & "','" & Celcom_Serviceid & "','" & receiverno & "','TT','" & Transaction_Id & "','1','1','6','0605040B8423F0','" & polymsg2 & "','" & SysTime & "','" & realcode & "','" & media & "','1','0','" & Sms_Type & "','0')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            ElseIf Mid$(receiverno, 3, 1) = 3 Then
                'MessageBox.Show("This is inside 013")
                Obcomm = New SqlCommand("insert into poly_trans(trans_id,code,mobile_no,telco,time_rcv)values('" & polyid & "','" & realcode & "','" & receiverno & "','013','" & SysTime & "')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                'MessageBox.Show("I finish insert into polytrans table")
                Obconn.Close()
                '##             www.planetunes.com/poly.....
                polymsg1 = "090601AE02056A0045C60D03706C616E6574756E65732E636F6D2F706F6C792F3F6D6F62696C656E6F3D" & tempstr3 & "2669643D" & tempstr
                '##                         Gaya Club
                polymsg2 = polymsg1 & "000103506C616E6574756E6573204D6F62696C65202D20" & tempstr2 & "000101"
                Obcomm = New SqlCommand("Insert into TmTouch_MT (short_code,price_code,telco,sender,service_id,destination,keyword,transaction_id,msg_id,msg_count,type,udh,detail,time_rcv,product_code,media_code,item_code,err_msg,sms_type,read_flag)values('" & ShortCode & "','" & TmTouch_Price & "','013','" & receiverno & "','" & TmTouch_Serviceid & "','" & receiverno & "','TT','" & Transaction_Id & "','1','1','6','0605040B8423F0','" & polymsg2 & "','" & SysTime & "','" & realcode & "','" & media & "','1','0','" & Sms_Type & "','0')", Obconn)
                Obconn.Open()
                Obcomm.ExecuteNonQuery()
                Obconn.Close()
            End If
            Status = "OK"
            Call store_record()
            Call close_record()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub send_2_push()
        Dim hexcode, str, strurl, receiverno, send_content, send_content1, send_content2, send_content3 As String
        Dim redeem_B4 As Integer
        Dim SysTime
        SysTime = DateTime.Now
        Try
            Obcomm = New SqlCommand("SELECT * FROM RT_Hex_Code WHERE Code='" & realcode & "'", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Obread.Read Then
                hexcode = Obread.GetValue(2)
            End If
            receiverno = Source_Mobtel
            Obconn.Close()
            Obcomm = New SqlCommand("select * from tt_member where mobile_no like '" & Source_Mobtel & "'", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Obread.Read Then
                redeem_B4 = Obread.GetValue(5)
                Obconn.Close()
                If redeem_B4 = 0 Then
                    Obcomm = New SqlCommand("Update TT_Member set free_redeem  = '1',status = '1' where mobile_no like '" & Source_Mobtel & "'", Obconn)
                    Obconn.Open()
                    Obcomm.ExecuteNonQuery()
                    Obconn.Close()
                End If
            Else
                'Send Error Msg to non member
                Call Handle_Error_Msg()
                Call close_record()
                Exit Sub
            End If
            If redeem_B4 = 0 Then
                Maxis_Price = "000"
                Maxis_Serviceid = "905"
                Digi_Price = "zf%2B6na155gqruYG9Y9kLnw%3D%3D"
                Celcom_Price = "0000"
                Celcom_Serviceid = "000"
                TmTouch_Price = "0000"
                TmTouch_Serviceid = "0"
                BillFlag = 0
                Maxis_Msg_Id = 0
                Digi_Msg_Id = 0
            Else
                Maxis_Price = "150"
                Maxis_Serviceid = "905"
                Digi_Price = "QlaLENu4bBuruYG9Y9kLnw%3D%3D"
                Celcom_Price = "0150"
                Celcom_Serviceid = "050"
                TmTouch_Price = "0150"
                TmTouch_Serviceid = "1"
                BillFlag = 1
                Maxis_Msg_Id = Transaction_Id
                Digi_Msg_Id = Transaction_Id
            End If
            'Send Ring Tone
            If itemcode = 1 Then
                Sms_Type = "Send_TT_RT"
                hexcode = Mid$(hexcode, 1, 256)
                If Mid$(receiverno, 3, 1) = 3 Then
                    'Dedicate to TmTouch User
                    Obcomm = New SqlCommand("Insert into TmTouch_MT (short_code,price_code,telco,sender,service_id,destination,keyword,transaction_id,msg_id,msg_count,type,udh,detail,time_rcv,product_code,media_code,item_code,err_msg,sms_type,read_flag)values('" & ShortCode & "','" & TmTouch_Price & "','013','" & receiverno & "','" & TmTouch_Serviceid & "','" & receiverno & "','TT','" & Transaction_Id & "','1','1','2','0B0504158100000003010101','" & hexcode & "','" & SysTime & "','" & realcode & "','" & media & "','" & itemcode & "','0','" & Sms_Type & "','0')", Obconn)
                    Obconn.Open()
                    Obcomm.ExecuteNonQuery()
                    Obconn.Close()
                ElseIf Mid$(receiverno, 3, 1) = 9 Then
                    'dedicate to celcom user
                    Obcomm = New SqlCommand("Insert into Celcom_MT (Short_Code,Price_Code,Telco,Sender,Service_id,Destination,Keyword,Transaction_id,Msg_id,Msg_count,type,udh,detail,time_rcv,product_code,media_code,item_code,err_msg,sms_type,read_flag)values('" & ShortCode & "','" & Celcom_Price & "','019','" & receiverno & "','" & Celcom_Serviceid & "','" & receiverno & "','TT','" & Transaction_Id & "','1','1','2','0B0504158100000003010101','" & hexcode & "','" & SysTime & "','" & realcode & "','" & media & "','1','0','" & Sms_Type & "','0')", Obconn)
                    Obconn.Open()
                    Obcomm.ExecuteNonQuery()
                    Obconn.Close()
                ElseIf Mid$(receiverno, 3, 1) = 6 Then
                    send_content = "0B0504158100000003010101" & hexcode
                    Obcomm = New SqlCommand("insert into Digi_MT(cpa_cp_id,cpa_cp_response_url,cpa_short_code,cpa_keyword,cpa_transaction_id,cpa_source_mobtel,cpa_destination_mobtel,cpa_charge_party,cpa_delivery_channel,cpa_prepaid_price_code,cpa_postpaid_price_code,cpa_status,cpa_error_code,cpa_content_sequence,cpa_max_content,cpa_content,cpa_ucp_message_type,product_code,media_code,item_code,time_rcv,type,read_flag)values('204','http%3A%2F%2F192.168.11.10%2FDiGi%2Fmt_response.asp','32132','TT','" & Digi_Msg_Id & "','" & receiverno & "','" & receiverno & "','S','SMS','" & Digi_Price & "','" & Digi_Price & "','1','1','1','1','" & send_content & "','4','" & realcode & "','" & media & "','1','" & SysTime & "','" & Sms_Type & "','0')", Obconn)
                    Obconn.Open()
                    Obcomm.ExecuteNonQuery()
                    Obconn.Close()
                ElseIf Mid$(receiverno, 3, 1) = 1 Then
                    'Dedicate to Maxis user
                    send_content = "0B0504158100000003010101" & hexcode
                    Call get_time()
                    Obcomm = New SqlCommand("Insert into Maxis_MT(Appid,Trackid,SenderNumber,DestinationAddress,OriginatingAddress,Messagecount,time_stamp,scheduleflag,scheduletime,billflag,serviceid,price,use_flash,m1,read_flag,service,time_rcv,sms_type,product_code,media_code,item_code)values('3085','" & Maxis_Msg_Id & "','" & receiverno & "','" & receiverno & "','32132','1','" & time_stamp2 & "','0','0','" & BillFlag & "','" & Maxis_Serviceid & "','" & Maxis_Price & "','0','" & send_content & "','0','TT','" & SysTime & "','Semd_RT_Push','" & realcode & "','" & media & "','1')", Obconn)
                    Obconn.Open()
                    Obcomm.ExecuteNonQuery()
                    Obconn.Close()
                Else
                    Status = "Error"
                    Call store_record()
                    Exit Sub
                End If
            Else
                Call Handle_Incorrect_Code()
                Exit Sub
            End If
            Status = "OK"
            Call store_record()
            Call close_record()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub close_record()
        Try
            Obcomm = New SqlCommand("Update TT_MO set Read_flag = '1' where originatingaddress = '" & Source_Mobtel & "'", Obconn)
            Obconn.Open()
            Obcomm.ExecuteNonQuery()
            MessageBox.Show("Another record solve")
            Obconn.Close()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub get_time()
        Dim month, day, year, hour, minute, second As String
        month = DatePart("m", Now)
        If Len(month) = 1 Then
            month = 0 & month
        End If
        day = DatePart("d", Now)
        If Len(day) = 1 Then
            day = 0 & day
        End If
        year = DatePart("yyyy", Now)
        hour = DatePart("h", Now)
        If Len(hour) = 1 Then
            hour = 0 & hour
        End If
        minute = DatePart("n", Now)
        If Len(minute) = 1 Then
            minute = 0 & minute
        End If
        second = DatePart("s", Now)
        If Len(second) = 1 Then
            second = 0 & second
        End If
        time_stamp2 = day & month & year & hour & minute & second
        'MessageBox.Show("This is the timestamp date>>" & time_stamp2 & "<<")
    End Sub
    Public Function URLencode(ByVal strdata As String) As String
        Dim i As Integer
        Dim strtemp As String
        Dim strchar As String
        Dim strout As String
        Dim intasc As Integer
        Try
            strtemp = Trim(strdata)
            For i = 1 To Len(strtemp)
                strchar = Mid$(strtemp, i, 1)
                intasc = Asc(strchar)
                If (intasc >= 48 And intasc <= 57) Or _
                    (intasc >= 97 And intasc <= 122) Or _
                    (intasc >= 65 And intasc <= 90) Then
                    strout = strout & strchar
                Else
                    strout = strout & "%" & Hex(intasc)
                End If
            Next i
            strout = Replace(strout, "%D%A", "%0d")
            strout = Replace(strout, "%A", "%0d")
            URLencode = strout
        Catch ex As Exception
        End Try
    End Function
    Private Sub Handle_Error_Msg()
        Status = "Error"
        Sms_Type = "Send_TT_MT_Error_Msg"
        'Change Price to 20 cents
        Maxis_Price = "000"
        Maxis_Serviceid = "905"
        Digi_Price = "u0shABRAVhmruYG9Y9kLnw%3D%3D"
        Celcom_Price = "0030"
        Celcom_Serviceid = "007"
        TmTouch_Price = "0030"
        TmTouch_Serviceid = "1"
        BillFlag = 0
        Maxis_Msg_Id = Transaction_Id
        Digi_Msg_Id = Transaction_Id
        Call Send_MT_Msg("Free Msg.Join TT & Be the first to get the latest hot ringtones weekly.Download 1 FREE mono/poly & enjoy 50% discount on all mono, poly. Send ON TT to 32132")
        Call store_record()
        Call close_record()
    End Sub
    Private Sub Check_Wait()
        Try
            Obcomm = New SqlCommand("select top 1 * from TT_Member where status=1 and waiting=0 and datediff(minute,time_rcv,getdate()) >10", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader()
            If Obread.Read Then
                content = "0"
                ShortCode = "32132"
                receiverno = Obread.GetValue(1)
                Obconn.Close()
                Call Set_Profile()
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Set_Profile()
        Dim Profile, HappyWait As String
        HappyWait = ""
        Try
            If LCase$(Microsoft.VisualBasic.Right$(content, 1)) = "p" Then
                'MessageBox.Show("I found that profile is P")
                Profile = "P"
            Else
                'MessageBox.Show("I found that profile is M")
                Profile = "M"
            End If
            Obcomm = New SqlCommand("select * from TT_member where mobile_no like '" & Source_Mobtel & "'", Obconn)
            Obconn.Open()
            Obread = Obcomm.ExecuteReader
            If Obread.Read Then
                HappyWait = Obread.GetValue(7)
                If HappyWait = 1 Then
                    'MessageBox.Show("Here is running if the waiting is 1")
                    'Change Price to 20 cents
                    Maxis_Price = "000"
                    Maxis_Serviceid = "905"
                    Digi_Price = "zf%2B6na155gqruYG9Y9kLnw%3D%3D"
                    Celcom_Price = "0000"
                    Celcom_Serviceid = "000"
                    TmTouch_Price = "0000"
                    TmTouch_Serviceid = "1"
                    Sms_Type = "Send_TT_MT_Set_Profile"
                    BillFlag = 0
                    Maxis_Msg_Id = Transaction_Id
                    Digi_Msg_Id = Transaction_Id
                Else
                    'MessageBox.Show("Here is running if the waiting is 0")
                    'No charge
                    Maxis_Price = "000"
                    Maxis_Serviceid = "905"
                    Digi_Price = "zf%2B6na155gqruYG9Y9kLnw%3D%3D"
                    Celcom_Price = "0000"
                    Celcom_Serviceid = "000"
                    TmTouch_Price = "0000"
                    TmTouch_Serviceid = "1"
                    Sms_Type = "Send_TT_List_MT_Push"
                    BillFlag = 0
                    Maxis_Msg_Id = 0
                    Digi_Msg_Id = 0
                End If
            End If
            Obconn.Close()
            '2nd MT Msg as push
            Maxis_Msg_Id = 0
            Digi_Msg_Id = 0
            Sms_Type = "Send_TT_List_MT_Push"
            If Profile = "M" Then
                'MessageBox.Show("We found M")
                If ThisWeekKeyword = "yz" Then
                    'MessageBox.Show("I found profile is M and send out MONO Tones for YZ")
                    Call Send_MT_Msg("Free Msg" & vbLf & "MonoTop10" & vbLf & "Y1-" & M(1) & vbLf & "Y2-" & M(2) & vbLf & "Y3-" & M(3) & vbLf & "Y4-" & M(4) & vbLf & "Y5-" & M(5) & vbLf & "Y6-" & M(6) & vbLf & "Y7-" & M(7) & vbLf & "Y8-" & M(8) & vbLf & "Y9-" & M(9) & vbLf & "Y10-" & M(10))
                ElseIf ThisWeekKeyword = "dp" Then
                    'MessageBox.Show("I found profile is M and send out MONO Tones for DP")
                    Call Send_MT_Msg("Free Msg" & vbLf & "MonoTop10" & vbLf & "D1-" & M(1) & vbLf & "D2-" & M(2) & vbLf & "D3-" & M(3) & vbLf & "D4-" & M(4) & vbLf & "D5-" & M(5) & vbLf & "D6-" & M(6) & vbLf & "D7-" & M(7) & vbLf & "D8-" & M(8) & vbLf & "D9-" & M(9) & vbLf & "D10-" & M(10))
                End If
            Else
                If ThisWeekKeyword = "yz" Then
                    'MessageBox.Show("I found profile is P and send out POLY Tones for YZ")
                    Call Send_MT_Msg("Free Msg" & vbLf & "PolyTop10" & vbLf & "Z1-" & P(1) & vbLf & "Z2-" & P(2) & vbLf & "Z3-" & P(3) & vbLf & "Z4-" & P(4) & vbLf & "Z5-" & P(5) & vbLf & "Z6-" & P(6) & vbLf & "Z7-" & P(7) & vbLf & "Z8-" & P(8) & vbLf & "Z9-" & P(9) & vbLf & "Z10-" & P(10))
                ElseIf ThisWeekKeyword = "dp" Then
                    'MessageBox.Show("I found profile is P and send out POLY Tones for DP")
                    Call Send_MT_Msg("Free Msg" & vbLf & "PolyTop10" & vbLf & "P1-" & P(1) & vbLf & "P2-" & P(2) & vbLf & "P3-" & P(3) & vbLf & "P4-" & P(4) & vbLf & "P5-" & P(5) & vbLf & "P6-" & P(6) & vbLf & "P7-" & P(7) & vbLf & "P8-" & P(8) & vbLf & "P9-" & P(9) & vbLf & "P10-" & P(10))
                End If
            End If
            If Profile = "M" Then
                If ThisWeekKeyword = "yz" Then
                    Call Send_MT_Msg("Free Msg.Choose Y1 to Y10.To d/load " & M(1) & ",type Y1 & send to 32132.Hurry!Redeem ur ONE FREE ringtone now. For poly,send TTP to 32132")
                ElseIf ThisWeekKeyword = "dp" Then
                    Call Send_MT_Msg("Free Msg.Choose D1 to D10.To d/load " & M(1) & ",type D1 & send to 32132.Hurry!Redeem ur ONE FREE ringtone now. For poly,send TTP to 32132")
                End If
            Else
                If ThisWeekKeyword = "yz" Then
                    Call Send_MT_Msg("Free Msg. Choose Z1 to Z10.Eg:To d/load " & P(1) & ", type Z1 & send to 32132.Hurry!Redeem ur ONE FREE ringtone now,following tones ONLY RM1.50 each")
                ElseIf ThisWeekKeyword = "dp" Then
                    Call Send_MT_Msg("Free Msg.Choose P1 to P10.To d/load " & P(1) & ", type P1 & send to 32132.Hurry!Redeem ur ONE FREE ringtone now,following tones ONLY RM1.50 each")
                End If
            End If
            'Update TT_Member table
            Obcomm = New SqlCommand("Update TT_Member set profile ='" & Profile & "',waiting ='1' where mobile_no ='" & receiverno & "'", Obconn)
            Obconn.Open()
            Obcomm.ExecuteNonQuery()
            Obconn.Close()
            'On Error Resume Next
            Call close_record()
        Catch ex As Exception
        End Try
    End Sub
End Class
 
Thank you so much,I can't really solve this problem because I'm still new to VB.NET. I wish someone really can help me in this. Thank you so much.

One thing that will help is  One thing that will help is

28-Dec-05 09:32 PM
which line throws the error?
The information can usually be obtained by catching this exception and printing the stack trace...

Hello  This is what I got,is that mean line 146??  Hello This is what I got,is that mean line 146??

28-Dec-05 10:07 PM
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The connection is already Open (state=Open).
   at System.Data.SqlClient.SqlConnection.Open()
   --- End of inner exception stack trace ---
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.VisualBasic.CompilerServices.LateBinding.FastCall(Object o, MethodBase method, ParameterInfo[] Parameters, Object[] args, Type objType, IReflect objIReflect)
   at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
   at Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
   at TT_Front.First.Distribution() in C:\Documents and Settings\Kam\My Documents\Visual Studio Projects\TT_Front\First.vb:line 165
   at TT_Front.First.Timer1_Tick(Object sender, EventArgs e) in C:\Documents and Settings\Kam\My Documents\Visual Studio Projects\TT_Front\First.vb:line 146
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
TT_Front
    Assembly Version: 1.0.2189.18783
    Win32 Version: 1.0.2189.18783
    CodeBase: file:///C:/Documents%20and%20Settings/Kam/My%20Documents/Visual%20Studio%20Projects/TT_Front/bin/TT_Front.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Data
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Drawing
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 7.0.5000.0
    Win32 Version: 7.10.6001.4
    CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
----------------------------------------
System.Xml
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.2032
    CodeBase: file:///c:/windows/assembly/gac/system.enterpriseservices/1.0.5000.0__b03f5f7f11d50a3a/system.enterpriseservices.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.

Cause  Cause

28-Dec-05 11:48 PM
Hi Drexler,

As can be seen from the exception text, a Connection.Open was executed when the connection is already open.  Looking at your code, it could have happened when an exception was encountered after the connection was opened but before it was closed.  Then along the way in your code, you opened the same connection and therefore encountering this error.

I would suggest that you put the closing of the connection in the Finally part of the Try Catch so that even if there's an exception raised, the connection will always be closed.  Here's a pseudo-code:

Try
Catch ex As Exception 
Finally
End Try
Thanks U Mr Ronald Francisco Good solution~!  Thanks U Mr Ronald Francisco Good solution~!
29-Dec-05 01:58 AM
Thank you so much Mr. Ronald Francisco,Ur solution solve the problem I face here. I just add in the "Finally"  as U said and my Engine running now. Thank you so much for helping me.

Happy New Year to U and everyone~!
Create New Account
help
in state persistence store .NET Framework Hi, I'm testing Web Approval Starter Kit with Visual Studio 2005 over Windows XP SP2, .NET Framework 3.0 & 3.5 versions installed. When try to complete an activity, the following error araises: System.InvalidOperationException was unhandled by user code Message = "Workflow with id \ "47773eee-c181-44a9-b045-30f5b7b1de51 \ " not Workflow.Runtime" Any idea? Thanks in advance .NET Discussions SQL Server (1) Windows XP (1) Visual Studio 2005 (1) InvalidOperationException (1) System.Workflow.Runtime (1) UidInstanceID (1) Database (1) WorkflowPersistence (1) Assume you use default found, in, state, persistence, store description: Hi, I'm testing Web Approval Starter Kit with Visual Studio 2005 over Windows XP SP2, .NET Framework 3.0 & 3.5 versions installed. When try
error 0x80070002 mobile development - camera Mobile Apps Hi, I am using Visual Studio 2005 with win 5 PC Pocket and Smartphone Emulators. 1. The CeCamera C api code VS 2005 prof.-try, win 5 - Pocket PC, Smartphone) The C# sample gives an 'System.InvalidOperationException' occurred in Microsoft.WindowsMobile.Forms.dll. 2. Can I use for example the videocap sample c api development). I hope that here it will be faster responsed. PocketPC Developer Discussions Visual Studio 2005 (1) Compact Framework (1) XP (1) SHCameraCapture (1) PostID (1) SiteID (1) CeCamera (1 PostID = 2480331&SiteID = 1 keywords: error, 0x80070002, mobile, development, -, camera description: Hi, I am using Visual Studio 2005 with win 5 PC Pocket and Smartphone Emulators. 1. The CeCamera C api code
Internal .Net Framework Data Provider error 6 .NET Framework We have started experiencing "System.InvalidOperationException: Internal .Net Framework Data Provider error 6" exceptions from our Visual Studio 2005 applications since implementing Mirroring with SQL Server 2005. If we change our connection string Source = Primary; Failover Partner = Mirror;Initial Catalog = Live;Uid = username;Pwd = password; Exception Message: - -- -- -- -- -- -- -- -- -- - System.InvalidOperationException: Internal .Net Framework Data Provider error 6. at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() ADO.NET Discussions SQL Server 2005 (1) Visual Studio 2005 (1) InvalidOperationException (1) DbConnectionPool (1) SqlConnection (1) ProviderBase (1) DbConnection (1) CreateObject (1) I think that we Jody keywords: Internal, .Net, Framework, Data, Provider, error, 6 description: We have started experiencing System.InvalidOperationException: Internal .Net Framework Data Provider error 6 exceptions from our Visual Studio 2005 appl
data is there, how do I go about adding a new record? When I tried, Visual Studio 2005 Pro gave me an InvalidOperationException, saying, when the control is data-bound." Am I just not able to add a it, add my data, then re-data-bind it? ADO.NET Discussions SQL Server (1) Visual Studio 2005 (1) InvalidOperationException (1) SqlConnection (1) DataAdapter (1) DataTable (1) AcceptChanges (1) EndEdit (1) Yup, if it's Author, Mentor, Dad, Grandpa Microsoft MVP (425) 556-9205 (Pacific time) Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition) _ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ What page is that described in your book? Is
net Vista and OleDb .NET Framework In our application we use C# programs created with Visual studio 2008 and .net framework 2.0 that read MDB files. One user reports that in it possible to repair Windows DAC in Windows Vista ? Any suggestion ? * ** ** ** ** ** ** * Testo dell'eccezione * ** ** ** ** ** ** * System.InvalidOperationException: I provider dati .Net Framework richiedono Microsoft Data Access Components (MDAC). Installare Microsoft Data Access keywords: .net, Vista, and, OleDb description: In our application we use C# programs created with Visual studio 2008 and .net framework 2.0 that read MDB files. One user reports that in