The given value of type String from the data source cannot be converted to type nvarchar of the specified target column

{tocify} $title={Table of Contents}


Issue


While working on a POC about moving data from CosmosDB to SQL using Azure Data factory, created a pipeline where I have mapped cosmos db records to sql table columns one to one, pretty simple. 

But when triggered the pipeline, it encountered following error-


given value of type String from the data source cannot be converted to type nvarchar





"message": "'Type=System.InvalidOperationException,Message=The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.



Why it happened


The error actually is for reason where when your database column length is less as compared to your length of the input.

But the error doesn't specify the exact column, so length of each column has to be checked, and there I found my silly mistake  😏.

While creating the table, I declared the datatype as nvarchar only and didn't specify the length to any of the cloumn i.e. I  didn't specify the the n - nvarchar(n)

n defines the string length that ranges from 1 to 4,000. If you don’t specify the string length, its default value is 1.




What to do


You need to decide beforehand the length of data you expect and accordingly set the length of columns, here as am working on POC I set it to maximum nvarchar(max).


If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!



Learn More about some more Azure Data Factory errors



Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post