Hi Team,
Am using to execute bellow C# code console application it is working fine but when am using script task to execute bellow C# code am getting error. Please help this issue ASAP.
My code:
#region Namespacesusing System;
using System.Data.SqlClient;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Xml;
#endregion
namespace ApiProfiler
{
class Program
{
static void Main(string[] args)
{
SqlConnection con;
SqlDataReader reader;
try
{
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["Profiler"].ConnectionString;
con = new SqlConnection(connection);
con.Open();
reader = new SqlCommand("SELECT TOP 100 profilerId,requestXML,responseXML FROM Profiler order by 1 desc", con).ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
// WriteAllText creates a file, writes the specified string to the file,
// and then closes the file. You do NOT need to call Flush() or Close().
string xmlRequest = Unzip((byte[])reader["requestXML"]);
XmlDocument docRQ = new XmlDocument();
docRQ.LoadXml(xmlRequest);
string jsonRQ = Newtonsoft.Json.JsonConvert.SerializeXmlNode(docRQ);
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static void CopyTo(Stream src, Stream dest)
{
byte[] bytes = new byte[4096];
int cnt;
while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0)
{
dest.Write(bytes, 0, cnt);
}
}
public static string Unzip(byte[] bytes)
{
//using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(new MemoryStream(bytes), CompressionMode.Decompress))
{
//gs.CopyTo(mso);
CopyTo(gs, mso);
}
return Encoding.UTF8.GetString(mso.ToArray());
}
}
}
}
Thanks Bala Narasimha