Base64 string in SSIS - ssis

I have a database table with a field "FileName" and a second field which is a base64 string (nvarchar(MAX)). It's an archive from my financial system. I want to convert this string back into a file using an Byte[] in a SSIS script task but i can't get the string value out of this object variable.
First I get the value from the SQL database in a SSIS variable (Base64Data). This variable is of type Object since the SQL type is nvarchar(MAX). I use sql statement: SELECT Base64Data FROM SubjectConnector WHERE FileName= '16-VMA-37041.pdf' which returns only one row. I then connect the Base64Data to a variable [User::Base64Data] in the Result Set window of the Execute SQL Task Editor. No problems here (at least so it seems).
But when I check the value of this object variable with:
MessageBox.Show(Dts.Variables["User::Base64Data"].Value.ToString());
it states:
System._ComObject
What it's going on? Is the result from the SQL query empty? How can I check this or what else is wrong?
Here's my SQL data
Please help.

Variable type Object is in fact ADO recordset, so you cannot get it directly with Dts.Variables... statement. I extracted NVARCHAR(MAX) value with FOR EACH enumerator for ADO.NET recordset, and fetched value from the first column into text variable.

Related

Copy Activity Data Factory V2 Collection Refrence to String type

I am trying to load the Json file to SQL Server using Data Factory V2. Need to save the collection Reference of type array to string in SQL Server. In below figure 'Field' object consist of multiple fields. I need to store the object 'Keywords' as string type in SQL Server DB mapped to single column. I am not able to map the 'Keywords' or 'Field' to column
In Data Factory, we can not load the json data keywords array to each row for one column as json string in SQL Server.
What we can figured out is load all the json data to one row in SQL Server.
But that is an unconventional way:
Set the json file as Delimiter file format.
Set the column and row Delimiter with the character which not exist
in file.
Then the json data will be considered as a json string like bellow:
The output in SQL database:

SSIS - change column meta data from byte stream to unicode string

I have an ADO Net Source to query data from an IBM AS/400. The column in question is of type CHAR (94). However, the meta data in SSIS shows it as a byte stream, DTS_BYTES. If I run the package, I get an error: data type of "output column "COLUMN_NAME" (38)" does not match the data type "System.String" of the source column "COLUMN_NAME". It's odd because in SSIS they are both set to DTS_BYTES as the data type.
If I go to the advanced editor for the ADO Net Source, it will let me change the data type of the external column to Unicode string, but not the output column.
I'm not sure why it's coming in as a byte string when the type CHAR should just show up as a string. (it does in other packages for other columns on the AS/400) How do I change this metadata so that it shows the external and output columns as Unicode strings instead of byte streams?
Thank you.

How to get json output in nvarchar, in SQL Server 2016

I used this Query to convert the data to JSON
SELECT *FROM tbl_subject FOR JSON AUTO
Iam getting the response as
when i click the response it is opening as XML file
how to change this xml to nvarchar data type
First of all, in SQL Server, JSON is not a data type in itself (XML is), but just a string representation.
What you see is due to how SQL Server Management Studio handles JSON when returned as a resultset. It is NOT xml, SSMS just slaps on an .xml file type, and prettifies the result. If you were to change how results were returned (Tools|Options|Query Results|SQL Server|General), you'd see it something like so:
JSON_F52E2B61-18A1-11d1-B105-00805F49916B
----------------------------------------------------------
[{"RowID":1,"UniversityID":1,"AcademicID":4,"CourseID":1}]
But this is just how SSMS returns result. If you were to execute your statement from an application, the result would be of string data type.
You could also change how you execute the query, to something like so:
DECLARE #nres nvarchar(max) = (SELECT * FROM dbo.tb_Subject FOR JSON AUTO)
SELECT #nres
Hope this helps!

Remove NEWLINE character in a SSIS Flat File

Is there a way to remove newline character from a flat file in SSIS ??... without a Script Task.
CONTEXT: I need to send all the content of a flat file as a single string value.
If you have access to some SQL database, you could try exporting the data of the flat file onto an SQL table in that database. The data would be loaded into multiple rows in SQL. Then all you need to do is to concatenate the data from all the rows.
TABLE STRUCTURE
DataRow
----
This
is a
really
good way.
Code to go into as SQL Statement
DECLARE #Data VARCHAR(MAX)
SELECT #Data = COALESCE(#Data + '', '') + DataRow
FROM YourTable
WHERE ISNULL(DataRow, '') <> ''
SELECT #Data
Then you can have the above SQL statements inside an Execute SQL Task and the output into a result set and map it onto some string variable, which can be used as per your wish.
I opted to write a simple method to read the entire file and write it to a single String variable, which was actually a DTS variable:
public String getFileData(FileInfo file)
{
string text = System.IO.File.ReadAllText(#file.FullName);
return text;
}
Use this expression in the sql query for the column with the new line character
select
RTRIM(LTRIM(REPLACE(REPLACE(REPLACE(ColumnWithNewLineChar,CHAR(9),''), CHAR(10),''),CHAR(13),''))) as ColumnWithOutNewLineChar from table
Tab, char(9). Line feed, char(10). Carriage return, char(13)
Above expression removes/replace the new line chars

SSIS package writing to CRM 2011 Data type error

We are trying to push a single order in to MS CRM (dev instance) via SSIS package.
Most of the columns coming from source (staging table) are of data type 'DT_STR' and their mapped fields in CRM are of 'DT_WSTR' data type.
I already looked for the solution on this site but in all cases the question is for converting wstr to str. In my case I need to convert str to wstr. when I run the package I get error saying,
Column xxxx cannot convert between unicode and non unicode string data type
I have already tried two solution:
1. Right click on the OLE source and convert datatype to wstr and
2. Using 'Data Conversion'
In both cases the error remains the same. Has anyone else had similar issue?
In OLE DB Source properties don't change data types. If you want you can change in
SELECT statement in OLE DB source.
you can change in 'Data Conversion'
Derived Column element
In Derived Column element code is:
(DT_WSTR, 50)([YourString])
Don't replace column, add new column in Derived column element.
You doing something wrong if you can't convert, you don't give real error message (or picture of your design), real error message is in Output window when you execute the package.