VB.NET - Error>>Exception has been thrown by the target of

Asked By Drexler Kan on 13-Feb-06 11:08 PM
Hello everyone,I'm a beginner in VB.NET. The following is my code,I'm migrating this module from VB to VB.NET. I'm really no idea with the messagebox pop-up written this= “Exception has been thrown by the target of an invocation”. Anyone can give me a help how to solve this problem please give me a solution,I have tried many times but still pop-up the same error. Hope someone can give me a help.
Thanks~!
Code:
Private Sub Sent_MT()
        Dim conStr As String
        Dim DB As String
        Dim sql As String
        Dim strURL, str As String
        Try
            If Telco = 2 Then
                Call get_time()
                MT_Msg = padQuotes(MT_Msg)
                conStr = "server=(local);database=Drexler;integrated security=true;"
                If Maxis_price <> "000" Then
                    sql = "Insert into " & Maxis_Table & "(Appid,trackid,sendernumber)values("
                    sql = sql & "'3085'" & " "                   'AppId
                    sql = sql & "'" & Trace_Id & "',"            'TrackId
                    sql = sql & "'" & OriginatingAddress & "',"  'SenderNumber
                    sql = sql & ")"
                Else
                    sql = "Insert into " & Maxis_Table & "(Appid,trackid,sendernumber)values("
                    sql = sql & "'3085'" & " "                   'AppId
                    sql = sql & "'" & Trace_Id & "',"            'TrackId
                    sql = sql & "'" & OriginatingAddress & "',"  'SenderNumber
                    sql = sql & ")"
                End If
            ElseIf Telco = 6 Then
            MT_Msg = URLencode(MT_Msg)
            sql = "INSERT INTO " & Digi_Table & "(cpa_keyword,cpa_destination_mobtel,cpa_delivery_channel,cpa_content) VALUES ("
            sql = sql & "'" & Service_Name & "',"
            sql = sql & OriginatingAddress & "',"
            sql = sql & "'SMS',"
            sql = sql & "'" & MT_Msg & "',"
            sql = sql &  " )"
            Obcomm10 = New SqlCommand(sql)
            Obconn10 = New SqlConnection(conStr)
            Obconn.Open()
            Obcomm10.ExecuteNonQuery()
            Obconn10.Close()
            Obconn10.dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Missing delimeters

Asked By drammer _ on 13-Feb-06 11:16 PM
for these:
  sql = sql & "'3085'" & " " 'AppId   (change the two similar lines)
should be: sql = sql & "'3085'" & ", " 'AppId 
  sql = sql & "'" & Service_Name & "',"
should be:   sql = sql & "'" & Service_Name & "','"

Sorry,its still the same error

Asked By Drexler Kan on 13-Feb-06 11:31 PM
I have changed what you asked me to do,but the messagebox still promp up with the same error="Exception has been thrown by the target of an invocation." Do you all have any other solution for this error?

error in connection string

Asked By Altaf Al-Amin on 13-Feb-06 11:40 PM
check connection string , this sort of error occured when there is somethign wrong with connection string. See msdn example for connection string. Do let me know if this was error.
Any idea?
Asked By Drexler Kan on 14-Feb-06 12:55 AM
Well,when I try to run the module. There is no problem if I am running with Telco=6. But there is problem when I test with Telco=2. So,do you think the connection string is the main problem? Because actually of of them used the same local host MS SQL Server.
modify your code
Asked By drammer _ on 14-Feb-06 02:34 AM
get conStr out of the if-else block and also these lines:
Obcomm10 = New SqlCommand(sql)
Obconn10 = New SqlConnection(conStr)
Obconn.Open()
Obcomm10.ExecuteNonQuery()
Obconn10.Close()
Obconn10.dispose()
This is how this module should do
Asked By Drexler Kan on 14-Feb-06 03:03 AM
I'm sorry,let me explain what I wish to do with this,actually the query will insert to different server. Telco=2 and Telco =6 and there are 4 more other Telco servers. Each of them using a different conStr. So I need to seperate the conStr to from each Telco. I'm using my PC to develop and test,so at this moment they are all in (local).
It was still showing the same error here. Do you have any idea to solve this?
Kindly post the entire code
Asked By drammer _ on 14-Feb-06 03:18 AM
so we will not be guessing a lot.