关于 Sql Server调用 .NET生成的dll所引发的问题

zorou_fatal 2005-06-08 07:27:43
问题陈述如下:
软件环境:

VS.net 2003
Sql Server 2000
Windows Server 2003

步骤1.在vs.net里建立了一个类库 名称为XmlConvertor代码如下:
using System;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Collections;
using System.IO;
using System.Net;


namespace XmlConvertor
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class XmlConvertor
{
private XmlDocument XD;
private XslTransform XT;


public XmlConvertor()
{
XD=new XmlDocument();
XT=new XslTransform();
//
// TODO: 在此处添加构造函数逻辑
//
}

public bool LoadXmlFile(string FileName)
{

XD.Load(FileName);
return (XD==null);
}

public string LoadXSLT(string FileName)
{
XPathDocument XPD=new XPathDocument(FileName);


//XmlUrlResolver resolver = new XmlUrlResolver();
//resolver.Credentials = CredentialCache.DefaultCredentials;
//try
//{
XT.Load(XPD.CreateNavigator(),null,null);
return "done";
//}
//catch(Exception e)
//{
// return e.Message.Replace("/n","");
//}

}

public void WriteHTML(string FileName)
{
MemoryStream t=new MemoryStream();
//try
//{
XT.Transform(XD,null,t,null);
string resultString = System.Text.UTF8Encoding.UTF8.GetString(t.ToArray());

if(!File.Exists(FileName))
{
FileStream fs=File.Create(FileName);
fs.Close();
StreamWriter sw=new StreamWriter(FileName,true,System.Text.Encoding.UTF8);
sw.Write(resultString);
sw.Close();

}
else
{
StreamWriter sw=new StreamWriter(FileName,false,System.Text.Encoding.UTF8);
sw.Write(resultString);
sw.Close();

}

//}
//catch
//{

//}

}

public string XMLDocument
{
get
{
return XD.OwnerDocument.ToString();
}
}

public string XSLTDocument
{
get
{
return XT.ToString();
}
}






}
}
编译后产生XmlConvertor.dll 然后按照帖子http://community.csdn.net/Expert/topic/3947/3947161.xml?temp=.3872949的做法执行
步骤二.dll部署完了,以后,我新建了一个空数据库Test建了一存储过程
CREATE PROCEDURE ConvertXML AS

DECLARE @object int
DECLARE @hr int
DECLARE @outinfo varchar(255)
DECLARE @source varchar(255)
DECLARE @property varchar(255)


EXEC @hr = sp_OACreate 'XmlConvertor.XmlConvertor', @object OUT

EXEC @hr = sp_OAMethod @object, 'LoadXmlFile',@property out,'C:\\Inetpub\\wwwroot\\tempxml\\test.xml'



IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object
RETURN
END








EXEC @hr = sp_OAMethod @object, 'LoadXSLT',@property out,'C:\\Inetpub\\wwwroot\\tempxml\\1.xslt'



IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object
RETURN
END




EXEC @hr = sp_OAMethod @object, 'WriteHTML',NULL,'C:\\Inetpub\\wwwroot\\tempxml\\1.html'

IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object
RETURN
END




EXEC @hr = sp_OADestroy @object
GO

步骤三 调试
用查询分析器调试,总是在LoadXSLT处出错,我一度怀疑是组件的问题,但是当我在别的工程里引用同位置下的dll并测试就可以通过。另外比较纳闷的是,如果我把1.xslt的内容删减到最精简的方式:
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
</xsl:stylesheet>
则可以在查询分析器里通过,即使形如
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
Test
</xsl:template>
</xsl:stylesheet>
的xslt也通不过。
请大家指教。

...全文
167 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zorou_fatal 2005-06-10
  • 打赏
  • 举报
回复
结帖,换了个办法实现目的。
chxljtt 2005-06-10
  • 打赏
  • 举报
回复
zorou_fatal 2005-06-09
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
版主白当了

将帖子提前。。。。。
zorou_fatal 2005-06-09
  • 打赏
  • 举报
回复
up
zorou_fatal 2005-06-09
  • 打赏
  • 举报
回复
谢谢楼上的同志。
我又测试了一下,从w3c处找的一个用来测试的xslt
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:choose>
<xsl:when test="system-property('xsl:version') >= 1.1">
<xsl:exciting-new-1.1-feature/>
</xsl:when>
<xsl:otherwise>
<html>
<head>
<title>XSLT 1.1 required</title>
</head>
<body>
<p>Sorry, this stylesheet requires XSLT 1.1.</p>
</body>
</html>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

非常有意思的是,如果我去掉这里的template那么,这个xslt可以被数据库里调用XmlConvertor.Dll的存储过程解析并产生文件。而如果我不去掉template,则只能被VS.net里的projects调用产生文件。
zeusvenus 2005-06-08
  • 打赏
  • 举报
回复
帮兄弟顶上去!
zorou_fatal 2005-06-08
  • 打赏
  • 举报
回复
To Saucer

I know what your suggestion mean.

I used to load xlst using "XT.Load(FileName)"

And in this way,the XmlConvertor.Dll was also working on well in VS.net projects while got the same error when used by SQL Server.

So,I guess if the reason lies in SQL Server
zorou_fatal 2005-06-08
  • 打赏
  • 举报
回复
干部今年聚会好玩嘛/
zorou_fatal 2005-06-08
  • 打赏
  • 举报
回复
To Saucer

Thank you for your attention.

The XmlConvertor.dll could work well in any VS.net projects.

And the error could only occur when the sp is trying to access the 1.xslt.

the error message is like below:

Error Source Description HelpFile HelpID
---------- ---------- ------------------------------------------------- -------- -----------
80131942 System.Xml file:///C:/Inetpub/wwwroot/tempxml/1.xslt(3,2) :
NULL 0

I guess there must be a "/n" in the entire message thus only part of it would appear.

dsclub 2005-06-08
  • 打赏
  • 举报
回复
虎哥,太长了,先帮你UP
saucer 2005-06-08
  • 打赏
  • 举报
回复
try to get the error message and post here, what if you do

XT.Load(FileName);
zorou_fatal 2005-06-08
  • 打赏
  • 举报
回复
up

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧