Click here to Skip to main content
11,789,710 members (66,180 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB ASP.NET

I am getting following exception.
Unable to connect to the remote server.
Could any one suggest me ?
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
        Dim intLoop As Integer
        Dim strSQL, strEmail, strUrl, strMessage, strHtml As String
        Dim strWebUrl As String
        Dim objDS As DataSet
        strUrl = ""
            ' Sending the DueList to admin
            strSQL = "Select email from t_Users where userlevel=0 and InstituteId=" & Val(Trim$("" & Session("InstId")))
            objDS = SQLGet(strSQL, "t_users")
            With objDS.Tables("t_users")
                If .Rows.Count Then
                    For intLoop = 0 To .Rows.Count - 1
                        mstrClass = Trim$("" & cmbClass.SelectedValue)
                        mstrSec = Trim$("" & cmbSec.SelectedValue)
                        strEmail = Trim$("" & .Rows(intLoop).Item(0))
                        strWebUrl = mstrWebURL & "Reports/rptSyllabusStatus.aspx?View=True" & "&C=" & mstrClass & "&S=" & mstrSec
                        strMessage = "<a href=" & strUrl & ">Click here to view the Fee Duelist</a>"
                        strHtml = Trim$("" & GetBodyText(strWebUrl))
                        strMessage = Trim$("" & GetReportMessage(Val(Trim$("" & Session("InstId"))), "SyllabusStatus"))
                        If Len(strMessage) = 0 Then
                            strMessage = "Please view the Class Syllabus Status  given below."
                        End If
                        strMessage = "To,<br>Respected Sir/Madam,<br>" & strMessage & "<br></br></br></br>" & strHtml
                        SendEmail(Val(Trim$("" & Session("InstId"))), strEmail, "Syllabus Status", strMessage)
                        'If gblnSend = False Then
                        '    ShowMessage("Please enter the valid Settings in the email settings screen", Page)
                        '    Exit Sub
                        'End If
                        ShowMessage("Mail has been sent to Administrator", Page)
                End If
            End With
        Catch ex As Exception
            SendErrorReport(Val(Trim$("" & Session("InstId"))), "frmSyllabusRep_Send", ex.Message)
        End Try
    End Sub

Public Function GetBodyText(ByVal astrUrl As String)
           Dim uri As New Uri(astrUrl)
           If (uri.Scheme = uri.UriSchemeHttp) Then
               Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
               request.Method = WebRequestMethods.Http.Get
               request.ContentType = "application/x-www-form-urlencoded"
               Dim oResponse As HttpWebResponse = request.GetResponse()
               Dim reader As New StreamReader(oResponse.GetResponseStream())
               Dim tmp As String = reader.ReadToEnd()
               GetBodyText = tmp
           End If
       Catch ex As Exception
           SendErrorReport(Val(gtxtInstId.Text), "Global-GetBodyText", ex.Message)
       End Try
       'Dim sHTMLResult As String = ""

       '    Dim HttpWReq As HttpWebRequest = WebRequest.Create(astrUrl)
       '    HttpWReq.KeepAlive = False
       '    Dim HttpWResp As HttpWebResponse = HttpWReq.GetResponse()
       '    sHTMLResult = New StreamReader(HttpWResp.GetResponseStream(), ASCII).ReadToEnd()
       '    GetBodyText = sHTMLResult
       'Catch ex As Exception
       '    SendErrorReport(Val(gtxtInstId.Text), "Global-GetBodyText", ex.Message)
       'End Try

   End Function
Posted 18-Nov-12 20:52pm
OriginalGriff at 19-Nov-12 3:04am
Where do you get the error - It could be the SQL or the email.
usharaniponnuru at 19-Nov-12 3:52am
am getting error on below line
Dim oResponse As HttpWebResponse = request.GetResponse()

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

"am getting error on below line
Dim oResponse As HttpWebResponse = request.GetResponse()"

Then you need to look at the values in the debugger - it could be anything, including a bad URL in astrUrl when the function is called.
Use the debugger to put a breakpoint on the first line of the function, and look at it. Then follow the code though by single-stepping and look at the values at each stage. You need to gather information at this point!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 999
1 Maciej Los 765
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 430

Advertise | Privacy | Mobile
Web04 | 2.8.1509028.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100