iT邦幫忙

0

[vb.net]一直頁面重新整,web service會當機

  • 分享至 

  • xImage

大家好:

正常是可以瀏覽,但如果網頁一直重新整理的話,webservice好像就會出錯(如下)..有時候是陣列索引超出範圍但我索引值都取範圍內,或者直接顯示無法指出的錯誤,接著其他WebMethod都不能用
想問有解決的方法嗎? 謝謝

https://ithelp.ithome.com.tw/upload/images/20210602/20097057idgOiuw5eZ.png

asp

dim SoapClient
set SoapClient = CreateObject("MSSOAP.soapClient30")
SoapClient.ClientProperty("ServerHTTPRequest") = True
SoapClient.mssoapinit "http://copp.com.tw/webservice/webservice/WebService1.asmx?WSDL"
stdata=SoapClient.userdata(udno,uname)
if stdata = "False" then
response.write "錯誤"
else

stArray=Split(stdata,",")
<%=stArray(0)%>
<%=stArray(1)%>
<%=stArray(2)%>
.
.
.
<%=stArray(6)%>
endif 

web service

 <WebMethod(Description:="資料")>
    Public Function userdata(uid As String, uname As String) As String
        Dim connetionString As String
        Dim conn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim reader As OleDbDataReader
        Dim sql As String
        Dim popdata(6) As String
        Dim LastStr As String
        connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &   Server.MapPath("../../st/db/db.mdb")
        conn = New OleDbConnection(connetionString) '連接資料庫
        Try
            conn.Open()
            sql = "Select *  From studdata where 編號 = """ & Trim(uid) & """and 姓名=""" & Trim(uname) & """"
            cmd = New OleDbCommand(sql, conn)
            reader = cmd.ExecuteReader()
            If reader.HasRows Then
                While reader.Read()
                    popdata(0) = reader("姓名")
                    popdata(1) = reader("E_mail")
                    popdata(2) = reader("密碼")
                    popdata(3) = reader("組別")
                    popdata(4) = reader("地址")
                    popdata(5) = reader("編號")
                    popdata(6) = reader("電話")
                    LastStr = Join(popdata, ",")
                    Return LastStr
                End While
            Else
                Return False
            End If
            conn.Close()
            Catch ex As Exception
            Return False
        End Try
    End Function

我把vb.net的陣列拿掉,asp只顯示soap導出的值,一直按重新整理 還是會"出現無法指出的錯誤",oledb的問題,在想是不是access資料庫連線問題..好像是資料庫lock住..

 Try
            conn.Open()
              sql = "Select *  From studdata where 編號 = """ & Trim(uid) & """and 姓名=""" & Trim(uname) & """"
            cmd = New OleDbCommand(sql, conn)
            reader = cmd.ExecuteReader()
            If reader.HasRows Then
                Return True
            Else
                Return False
            End If
            popdata = Nothing
            reader.Close()
            conn.Close()
            conn = Nothing

        Catch ex As Exception
            Throw
        End Try

asp

dim SoapClient
set SoapClient = CreateObject("MSSOAP.soapClient30")
SoapClient.ClientProperty("ServerHTTPRequest") = True
SoapClient.mssoapinit "http://copp.com.tw/webservice/webservice/WebService1.asmx?WSDL"
stdata=SoapClient.userdata(udno,uname)
response.write stdata
陣列沒防呆...所以超過索引~
mayyola iT邦研究生 1 級 ‧ 2021-06-03 14:33:16 檢舉
剛剛測試,應該是在回傳值前先把OleDbDataReader、OleDbConnection等連線先關閉,這樣資料庫不會被鎖住 謝謝!
自己找到問題解決~~不錯唷~
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答