public static SqlXml ExecScript(SqlString Sql, SqlXml Options, SqlXml Input) { var XOutput = new XDocument( new XElement("root", new XElement("content"))); try { using (var q = new SqlCommand()) { q.Connection = new SqlConnection("context connection=true"); q.CommandType = CommandType.Text; q.CommandText = Sql.Value; q.InitOptions(Options.Value); q.Parameters.SetInput(Input.Value); q.Connection.Open(); q.ExecuteNonQuery(); XOutput.Root.Add(q.Parameters.GetOutput()); q.Connection.Close(); } } catch (Exception ex) { XOutput.Root.Add(ex.ExceptionSerialize()); } return new SqlXml(XOutput.CreateReader()); }
public static SqlXml ExecQuery(SqlString Sql, SqlXml Options, SqlXml Input) { var XOutput = new XDocument(new XElement("root")); try { using (var q = new SqlCommand()) { q.Connection = new SqlConnection("context connection=true"); q.CommandType = CommandType.Text; q.CommandText = Sql.Value; q.InitOptions(Options.Value); q.Parameters.SetInput(Input.Value); q.Connection.Open(); var Result = q.ExecuteXmlReader(); if (Result.Read()) XOutput.Root.Element("content").Add( XElement.Load(Result, LoadOptions.None)); q.Connection.Close(); } } catch (Exception ex) { XOutput.Root.Add(ex.ExceptionSerialize()); } return new SqlXml(XOutput.CreateReader()); }