Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SSIS中脚本任务调用TSQL存储过程时使用空XML变量_C#_Sql Server_Xml_Stored Procedures_Ssis - Fatal编程技术网

C# SSIS中脚本任务调用TSQL存储过程时使用空XML变量

C# SSIS中脚本任务调用TSQL存储过程时使用空XML变量,c#,sql-server,xml,stored-procedures,ssis,C#,Sql Server,Xml,Stored Procedures,Ssis,我有一个SSIS包,它使用脚本任务从SQL任务输出xml文件。SQL任务调用一个存储过程。存储过程将创建xml输出结果并插入ssis变量中,以便脚本任务可以创建实际的xml文件。只要存储过程不使用xml数据类型的(内部)变量,所有这些都可以正常工作 换句话说,如果您像这样对存储过程进行编码,它可以正常工作: SELECT ABC FROM Table FOR XML PATH etc. 但如果在存储过程中使用如下变量: DECLARE @X1 XML SET @X1 = (SELECT A

我有一个SSIS包,它使用脚本任务从SQL任务输出xml文件。SQL任务调用一个存储过程。存储过程将创建xml输出结果并插入ssis变量中,以便脚本任务可以创建实际的xml文件。只要存储过程不使用xml数据类型的(内部)变量,所有这些都可以正常工作

换句话说,如果您像这样对存储过程进行编码,它可以正常工作:

SELECT ABC
FROM Table
FOR XML PATH etc. 
但如果在存储过程中使用如下变量:

DECLARE @X1 XML
SET @X1 = 
(SELECT ABC 
 FROM TABLE
 FOR XLM PATH etc )
SELECT @X1
//string Data = Dts.Variables["XMLcode"].Value.ToString();
  string Data = Dts.Variables["XMLcode"].Value.ToString().Replace("<ROOT>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>").Replace("</ROOT>", "");
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(Data.ToString());
            string outputFile = Dts.Variables["FilePath"].Value.ToString() + "\\" + Dts.Variables["FileName"].Value.ToString();
            xdoc.Save(outputFile);
            Dts.TaskResult = (int)ScriptResults.Success;
然后,脚本任务会给出一个SSIS错误:

MSSQLError HResult=“0x80004005”Source=“Microsoft SQL Server XML扩展”Description=“未提供说明”?>

如何防止此错误?

在SSMS中运行代码可以正常工作,但脚本任务似乎不能很好地处理SP中的变量,即使数据类型从未更改(与不在SP中使用变量相比)

SSIS变量是字符串类型(据我所知,SSIS中没有xml类型)。脚本在MS Visual C#2008中,部分代码如下所示:

DECLARE @X1 XML
SET @X1 = 
(SELECT ABC 
 FROM TABLE
 FOR XLM PATH etc )
SELECT @X1
//string Data = Dts.Variables["XMLcode"].Value.ToString();
  string Data = Dts.Variables["XMLcode"].Value.ToString().Replace("<ROOT>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>").Replace("</ROOT>", "");
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(Data.ToString());
            string outputFile = Dts.Variables["FilePath"].Value.ToString() + "\\" + Dts.Variables["FileName"].Value.ToString();
            xdoc.Save(outputFile);
            Dts.TaskResult = (int)ScriptResults.Success;
//string Data=Dts.Variables[“XMLcode”].Value.ToString();
字符串数据=Dts.Variables[“XMLcode”].Value.ToString().Replace(“,”).Replace(“,”);
System.Xml.XmlDocument xdoc=新的XmlDocument();
xdoc.LoadXml(Data.ToString());
字符串outputFile=Dts.Variables[“FilePath”].Value.ToString()+“\\”+Dts.Variables[“FileName”].Value.ToString();
保存(输出文件);
Dts.TaskResult=(int)ScriptResults.Success;

我在SP中使用xml数据类型变量的原因是我必须使用xml.modify。

是否使用ADO.net连接?为了返回XML结果,只需使用ADO.NET连接管理器


。在ADO.NET中,您需要将参数作为@para而不是?

Aha传递,我使用了OLEDB,但现在它可以工作了。实际上,我找到了自己的解决方案,那就是将存储过程中的变量转换为NVARCHAR(MAX)。