I am using a script task to generate a json file from a sql query.
The c# code in the script task:
public void Main()
{
// TODO: Add your code here
ConnectionManager cm;
string sqlString = "";
System.IO.StreamWriter file = new System.IO.StreamWriter(@"f:\JSONOutput.txt");
sqlString = "SELECT * FROM[dbo].[JJVCACUProductElectron] where id in (1,2,3) for json auto";
System.Data.SqlClient.SqlConnection sqlConn;
System.Data.SqlClient.SqlCommand sqlComm;
cm = Dts.Connections["crm_vm_2017_cs_dotnet"];
sqlConn = (System.Data.SqlClient.SqlConnection)cm.AcquireConnection(Dts.Transaction);
sqlComm = new System.Data.SqlClient.SqlCommand(sqlString, sqlConn);
System.Data.SqlClient.SqlDataReader reader = sqlComm.ExecuteReader();
try
{
while (reader.Read())
{
file.WriteLine(reader[0]);
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
cm.ReleaseConnection(sqlConn);
Dts.TaskResult = (int)ScriptResults.Success;
}
The generated output file is incomplete, I guess there is probably a return in some column. How to remove the return characters in the output ?