简体   繁体   中英

What's wrong with my ASP.NET / Visual Basic code?

I'm new to ASP.NET / Visual basic. I'm trying to create a simple get request to get the data from the database. But whenever the page loads, I get a generic 500 server error code in the console. Here is my ASP.NET code:

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <script>
        var dataSource = new kendo.data.DataSource({ transport: {
                                read:  {
                                        url: "/webservices/alertService.asmx/GetAlert",
                                        dataType: "json"
                                        },
                                update: {
                                        url: "/webservices/alertService.asmx/UpdateAlert",
                                        dataType: "json"
                                        }
                         }});
        var alertObj = dataSource.read();
        console.log("alertObj: ", alertObj);
        var pageBody = document.getElementById('page-body');
        
        pageBody.innerHTML = "<h1>Website alert page is currently being built...</h1><br/>" +
                             "<p>" + alertObj.alert_title + "</p><br/>"  +
                             "<p>" + alertObj.alert_body + "</p><br/>"  
    </script> 

    <div id="page-body"></div>

</asp:content>

Here is my Visual Basic code:

<%@ WebService Language="VB" Class="MapService" %>

Imports System
Imports System.IO
Imports System.Security
Imports System.Configuration
Imports System.Xml
Imports System.Web
Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Xml.Serialization
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Data.Odbc
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Collections.Generic
Imports Newtonsoft.Json
Imports System.Net.Http

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class MapService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Sub GetAlert()
    Dim xmlString As String = ""

    Try
        Dim sConnString As String = ConfigurationManager.ConnectionStrings("WebApp").ConnectionString
        Dim odbcConn As OdbcConnection = New OdbcConnection(sConnString)
    
        Dim sQueryString As String = "SELECT * FROM tblalert WHERE alert_id = 1"
        Dim DBCommand As New OdbcCommand(sQueryString, odbcConn)
        odbcConn.Open()

        Try

            Dim odbcReader As OdbcDataReader = DBCommand.ExecuteReader(CommandBehavior.CloseConnection)
            While odbcReader.Read()
    
                xmlString += "{"
                xmlString += """alert_id"":""" & Convert.ToInt16(odbcReader("alert_id")) & ""","
                xmlString += """alert_title"":""" & Trim(odbcReader("alert_title").ToString) & ""","
                xmlString += """alert_body"":""" & Trim(odbcReader("alert_body").ToString) & ""","
                xmlString += """show_alert"":""" & Convert.ToInt16(odbcReader("show_alert")) & ""","
                xmlString += "}"

            End While

            odbcReader.Close()

        Catch ex As Exception

            odbcConn.Close()

        End Try

        odbcConn.Close()

    Catch ex As Exception

    End Try

    'xmlString = xmlString.Trim().Substring(0, xmlString.Length - 1)
    'xmlString = "[" & xmlString & "]"

    HttpContext.Current.Response.BufferOutput = True
    HttpContext.Current.Response.ContentType = "application/x-javascript"
    HttpContext.Current.Response.Write(xmlString)
    HttpContext.Current.Response.Flush()

End Sub

What is wrong with my code? Why is the "dataSource.read()" function not getting the data from the VB file?

According to this web-site http://net-informations.com/q/mis/500.html the problem is on your server side. Something isn't configured correctly. Double check the connection string you are using to make sure it is connecting to the right server and then check to make sure the server is running and accessible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM