繁体   English   中英

我的 ASP.NET / Visual Basic 代码有什么问题?

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

我是 ASP.NET / Visual Basic 的新手。 我正在尝试创建一个简单的获取请求以从数据库中获取数据。 但是每当页面加载时,我都会在控制台中收到一个通用的 500 服务器错误代码。 这是我的 ASP.NET 代码:

<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>

这是我的 Visual Basic 代码:

<%@ 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

我的代码有什么问题? 为什么“dataSource.read()”function没有从VB文件中获取数据?

根据这个网站http://net-informations.com/q/mis/500.html问题出在您的服务器端。 某些配置不正确。 仔细检查您使用的连接字符串以确保它连接到正确的服务器,然后检查以确保服务器正在运行并且可以访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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