public static void DumpTableToFile(SqlConnection connection, string tableName, string fieldsName, string filterCond, string customerCodeEnv, int commandTimeout) { string fileName = String.Format("{0}.csv", tableName.ToLower()); string destinationFile = Path.Combine(Path.GetTempPath(), fileName); string whereCond = ""; if (filterCond != null) { whereCond = String.Format(" WHERE {0}", filterCond); } SqlTransaction trans; trans = connection.BeginTransaction(IsolationLevel.ReadUncommitted); using (var command = new SqlCommand("SELECT " + fieldsName + " FROM " + tableName + whereCond, connection)) { command.CommandTimeout = commandTimeout; command.Transaction = trans; TableDumper.readerToFile(command, destinationFile); } CompressFile(fileName, destinationFile); S3Uploader.upload(destinationFile + ".gz", String.Format("{0}/{1}.gz", customerCodeEnv, fileName), "ecpr"); }
public static void runQueryToFile(SqlConnection connection, string runQuery, string fileName, string customerCodeEnv, int commandTimeout, string resultType) { string destinationFile = Path.Combine(Path.GetTempPath(), fileName); using (var command = new SqlCommand(runQuery, connection)) { command.CommandTimeout = commandTimeout; if (resultType == "csv") { TableDumper.readerToFile(command, destinationFile); } else { TableDumper.readerToFile_JSON(command, destinationFile); } } CompressFile(fileName, destinationFile); S3Uploader.upload(destinationFile + ".gz", String.Format("{0}/{1}.gz", customerCodeEnv, fileName), "ecpr"); }