2014-02-10 43 views
-1

我有一個運行時訪問數據庫的功能齊全的網站,所以我決定升級它的MSSQL,結果比其他時候更困難。記錄集中的替換錯誤「800a005e」

我有一個錯誤稱爲800a005e

這是我的函數:

Function EscapeSpecialCharacters(ByVal strRSContent) 
    strRSContent = Replace(strRSContent,"&","&") 
    strRSContent = Replace(strRSContent,"É","É") 
    strRSContent = Replace(strRSContent,"é","é") 

    strRSContent = Replace(strRSContent,"Æ","Æ") 
    strRSContent = Replace(strRSContent,"Ø","Ø") 
    strRSContent = Replace(strRSContent,"Å","Å") 
    strRSContent = Replace(strRSContent,"æ","æ") 
    strRSContent = Replace(strRSContent,"ø","ø") 
    strRSContent = Replace(strRSContent,"å","å") 

    EscapeSpecialCharacters = strRSContent 
End Function 

這是我如何調用的樂趣:

If Not isNull(strPageContent) Then 
    Response.Write strPageContent 
End If 

通知,一切工作正常,當我有它在訪問數據庫上,但現在又是另一回事了!

+0

我們不記住錯誤代碼。你能告訴我們錯誤信息的*文本嗎?另外什麼是'strRSContent'的數據類型,以及如何從數據庫填充該變量? –

+0

爲什麼不使用HTMLEncode? http://www.w3schools.com/asp/met_htmlencode.asp – Fionnuala

+0

對不起...這是一個很好的;-) 錯誤是這樣的: Microsoft VBScript運行時錯誤'800a005e' 無效的使用空':'替換」 /includes/functions.asp,7號線 這是第一線_replace(strRSContent, 「&」, 「& 」)_ – Daniel

回答

-1

有時是有點沮喪與全部的IsEmpty,ISNULL,等等。我使用自定義功能來避免這些問題:

Public Function IsNullOrEmpty(strString) 
    strString = Trim(strString) 

    If IsEmpty(strString) Then 
    IsNullOrEmpty = True 
    Exit Function 
    ElseIf StrComp(strString, "") = 0 Then 
    IsNullOrEmpty = True 
    Exit Function 
    ElseIf IsNull(strString) Then 
    IsNullOrEmpty = True 
    Exit Function 
    Else 
    IsNullOrEmpty = False 
    Exit Function 
    End If 
End Function 

Function EscapeSpecialCharacters(ByVal strRSContent) 
    If IsNullOrEmpty(strRSContent) Then 
     EscapeSpecialCharacters = "" 
     Exit Function 
    End If 

    strRSContent = Replace(strRSContent,"&","&") 
    strRSContent = Replace(strRSContent,"É","É") 
    strRSContent = Replace(strRSContent,"é","é") 

    strRSContent = Replace(strRSContent,"Æ","Æ") 
    strRSContent = Replace(strRSContent,"Ø","Ø") 
    strRSContent = Replace(strRSContent,"Å","Å") 
    strRSContent = Replace(strRSContent,"æ","æ") 
    strRSContent = Replace(strRSContent,"ø","ø") 
    strRSContent = Replace(strRSContent,"å","å") 

    EscapeSpecialCharacters = strRSContent 
End Function 

所以你的情況應該工作無論DB:

Dim strPageContent 
strPageContent = EscapeSpecialCharacters(RecSetPageContent("pagecontent")) 
+0

對不起,我遲到了!我有這樣的說法: 如果RecSetPageContent(「pagecontent」)<>「」然後strPageContent = EscapeSpecialCharacters(RecSetPageContent(「pagecontent」))如果沒有isNull(strPageContent)然後Response.Write strPageContent結束如果「 ) 這是不允許的由於某種原因...可能是因爲有換行符或代碼(
/)?因爲一個正常的「<%Response.Write RecSetPageContent(」pagecontent「)%>」沒有問題... – Daniel

+0

不,我不這麼認爲,這不是錯誤的建議,有些數據庫返回空,一些空。你可以嘗試交換IsNull到IsEmpty或使用我的函數。看我的編輯。 – stare

-1

功能改成這樣處理的情況下,當輸入爲空:

Function EscapeSpecialCharacters(ByVal strRSContent) 
    If IsNull(strRSContent) Then 
     EscapeSpecialCharacters = "" 
     Exit Function 
    End If 

    strRSContent = Replace(strRSContent,"&","&amp;") 
    strRSContent = Replace(strRSContent,"É","&Eacute;") 
    strRSContent = Replace(strRSContent,"é","&eacute;") 

    strRSContent = Replace(strRSContent,"Æ","&AElig;") 
    strRSContent = Replace(strRSContent,"Ø","&Oslash;") 
    strRSContent = Replace(strRSContent,"Å","&Aring;") 
    strRSContent = Replace(strRSContent,"æ","&aelig;") 
    strRSContent = Replace(strRSContent,"ø","&oslash;") 
    strRSContent = Replace(strRSContent,"å","&aring;") 

    EscapeSpecialCharacters = strRSContent 
End Function 

SQL Server返回Null時可能會返回空字符串。

+0

對不起,我遲到了!不是它是空的,因爲如果我等,選擇我的metas作爲特定的pageid(或pagecontent),數據應該寫入頁面,但它不會。但是,如果我在MSSQL中進行相同的查詢,則應該按照它應該選擇的每個信息。因此,問題不在於SQL(並且我沒有任何包含「NULL」的字段)。 – Daniel

+0

@丹尼爾是的,它是空的,這是唯一的方法'替換'會拋出這樣的錯誤。字段不需要明確地具有空值,缺少任何其他值也是空的。如果你會發布你的SQL,也許我可以幫助你更深入地追蹤它。 –