【问题标题】:ASP Classic, SQL 2008, XML Output, and DSN vs DSN-Less Produces Chinese LettersASP Classic、SQL 2008、XML 输出和 DSN vs DSN-Less 生成中文字母
【发布时间】:2010-04-28 19:19:54
【问题描述】:

在过去的一个月里,我一直遇到问题,似乎无法找出问题所在。这是设置和一点背景。

背景:

我有一个 Web 主机,他在 Windows Server 2003 和 SQL Server 2000 上运行我的网站。我的一个网页从 SQL 服务器的存储过程中返回了一个结果集作为 xml。下面是代码:

存储过程:

select top 10
    1 as tag
    , null as parent
    , column1 as [item!1!column1!element]
    , column2 as [item!1!column2!element]
from
    table1

for XML EXPLICIT

ASP 页面:index.asp

Call OpenConn

Set cmd = Server.CreateObject("ADODB.Command")
With cmd
 .ActiveConnection = dbc
 .CommandText = "name of proc"
 .CommandType = adCmdStoredProc

 .Parameters.Append .CreateParameter("@RetVal", adInteger, adParamReturnValue, 4)
 .Parameters.Append .CreateParameter("@Level", adInteger, adParamInput, 4, Level)
End With

Set rsItems = Server.CreateObject("ADODB.Recordset")
With rsItems
 .CursorLocation = adUseClient
 .CursorType = adOpenStatic
 .LockType = adLockBatchOptimistic
 Set .Source = cmd
 .Open
 Set .ActiveConnection = Nothing
End With

If NOT rsItems.BOF AND NOT rsItems.EOF Then

 OutputXMLQueryResults rsItems,"items"

End If

Set rsItems = Nothing
Set cmd = Nothing

Call CloseConn



Sub OpenConn()
 strConn = "Provider=SQLOLEDB;Data Source=[hidden];User Id=[hidden];Password=[hidden];Initial Catalog=[hidden];"
 Set dbc = Server.CreateObject("ADODB.Connection")
 dbc.open strConn
End Sub

Sub CloseConn()
 If IsObject(dbc) Then
  If dbc.State = adStateOpen Then
   dbc.Close
  End If
  Set dbc = Nothing
 End If
End Sub

Sub OutputXMLQueryResults(RS,RootElementName)
 Response.Clear
 Response.ContentType = "text/xml"
 Response.Codepage = 65001
 Response.Charset = "utf-8"
 Response.Write ""
 Response.Write ""
 While Not RS.EOF
  Response.Write RS(0).Value
  RS.MoveNext
 WEnd
 Response.Write ""
 Response.End
End Sub

现在:

一切都很好,直到我的主机升级到 Windows Server 2008 和 SQL Server 2008。突然之间我得到了这样的结果:

来自浏览器:

Chinese Characters: Browser http://iphone.rolyrolls.com/chineseChars1.png

从查看源代码:

Chinese Characters: View Source http://iphone.rolyrolls.com/chineseChars2.png

但是,我发现如果我使用 DSN 连接 strConn = "DSN=[my DSN Name];User Id=[hidden];Password=[hidden];Initial Catalog=[hidden];" 效果很好!

我当前的主机将不再支持 DSN,但这超出了此问题的范围。有人告诉我使用 ADO.Stream 对象而不是 Recordset 对象,但我不确定如何实现。

问题:

有没有人遇到过这个问题并找到解决方法?

那个ADO.Stream 对象怎么样,有人可以帮我提供一个适合我的代码的示例吗?

【问题讨论】:

  • 如果您可以访问您的数据库,通过查询分析器或 sql 管理工作室看到的输出如何?这是您希望您的 ASP 页面显示的内容吗?
  • 它准确地显示了我想要的。一个普通的 xml 文件,没有在我的代码中添加到响应中的初始行 `

标签: sql xml asp-classic ado dsn


【解决方案1】:

您可能想查看connectionstrings.com


编辑

对我来说这似乎是一个数据库驱动程序问题 - 哪个驱动程序使用了您的 DSN 连接?

更新

connectionstrings.com 列出了与 Provider=SQLNCLI10 的 SQL Native 连接,但是当我为该提供程序生成一个 .udl 连接文件时,它显示为 Provider=SQLNCLI10.1,所以这可能值得一试(如果您还没有尝试过的话)。

【讨论】:

  • 是的。我去过那里,做到了,尝试了所有适用的方法。没有任何效果。
  • 我的 DSN 连接使用 SQL Server Native Client 10.0
  • 是的,当我的第一个诊断是尝试我在 connectionstrings.com 中看到的每个提供商时,我确实尝试了 SQLNCLI10SQLNCLI10.1。为了理智,我会再次尝试...10.1
  • 好的,SQLNCLI10SQLNCLI10.1 不起作用的原因是我收到一条错误消息:Provider cannot be found. It may not be properly installed. 将与托管公司讨论此问题。并为您提供最新信息。
  • 这很有趣,这是我的网络托管公司的回复:In order to connect to MSSQL through an ASP script you will need to use Provider=SQLOLEDB instead of Provider=SQLNCLI10 which is incorrect on our architecture. Once those connections provider settings are updated you should be good to go. 我受够了这家托管公司。在过去的 12 年里,他们一直很棒。但现在似乎是另一家公司买下了它们,而我一直遇到问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 2018-04-21
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 2019-09-23
相关资源
最近更新 更多