我在 SQL Server 2008 CLR 项目中有一个存储过程。此函数使用包含一些 xml 的参数调用控制台应用程序。
[Microsoft.SqlServer.Server.SqlProcedure()]
public static SqlInt32 ExecuteApp(SqlString utilPath, SqlString arguments, ref SqlString result)
{
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
Process p = new Process();
try
{
//ProcessStartInfo to run the DOS command attrib
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
info.Arguments = string.Format(@"/c ""{0}"" {1}", utilPath, arguments);
SqlContext.Pipe.Send(info.Arguments);
p.StartInfo = info;
p.Start();
String processResults = p.StandardOutput.ReadToEnd();
SqlContext.Pipe.Send(processResults);
result = processResults;
if (String.IsNullOrEmpty((String)result))
result = p.StandardError.ReadToEnd();
return 1;
}
finally
{
p.Close();
}
}
这里的问题是包含 xml 的参数。这是执行存储过程的表达式:
declare @Result nvarchar(max)
exec ExecuteApp 'C:\Console.exe', 'send "<messages><message>my message</message></messages>"', @Result out
select @Result
执行存储过程后,出现如下错误:
<此时是出乎意料的。
我想注意到没有 xml 一切正常。