Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET
Hi,
 
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 = ""
 
        Try
            '---------------------------------
            ' 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)
                    Next
                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)
 
       Try
           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
               oResponse.Close()
           End If
       Catch ex As Exception
           SendErrorReport(Val(gtxtInstId.Text), "Global-GetBodyText", ex.Message)
       End Try
 
       'Dim sHTMLResult As String = ""

       'Try
       '    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
v2
Comments
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
good
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!
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,631
1 Sergey Alexandrovich Kryukov 6,345
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
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