IT TIP

패키지 가져 오기 오류-유니 코드와 비 유니 코드 문자열 데이터 형식간에 변환 할 수 없음

itqueen 2020. 11. 19. 22:43
반응형

패키지 가져 오기 오류-유니 코드와 비 유니 코드 문자열 데이터 형식간에 변환 할 수 없음


SQL Server 2008을 사용하여 컴퓨터에 dtsx 패키지를 만들었습니다. 세미콜론으로 구분 된 csv 파일의 데이터를 모든 필드 유형이 NVARCHAR MAX 인 테이블로 가져옵니다.

내 컴퓨터에서 작동하지만 클라이언트 서버에서 실행해야합니다. 동일한 csv 파일 및 대상 테이블로 동일한 패키지를 만들 때마다 위의 오류가 발생합니다.

패키지 생성을 단계별로 진행했으며 모든 것이 정상인 것 같습니다. 매핑은 모두 정확하지만 마지막 단계에서 패키지를 실행하면이 오류가 발생합니다. 그들은 SQL Server 2005를 사용하고 있습니다.

누구든지이 문제를 찾기 시작할 곳을 조언 할 수 있습니까?


유니 코드가 아닌 소스에서 유니 코드 SQL Server 테이블로 변환하는 문제는 다음을 통해 해결할 수 있습니다.

  • 데이터 흐름에 데이터 변환 단계 추가
  • 데이터 변환을 열고 적용되는 각 데이터 유형에 대해 유니 코드를 선택하십시오.
  • 적용 가능한 각 열의 출력 별칭을 기록해 둡니다 (기본적으로 [원본 열 이름]의 복사본으로 명명 됨).
  • 이제 대상 단계에서 매핑을 클릭하십시오.
  • 모든 입력 매핑을 이전 단계에서 별칭이 지정된 열에서 가져 오도록 변경합니다 (이 단계는 쉽게 간과되고 여전히 동일한 오류가 발생하는 이유를 궁금해하게됩니다).

어떤 시점에서 nvarchar열을 varchar열로 (또는 그 반대로) 변환하려고합니다 .

또한 모든 것이 (아마도) 왜 nvarchar(max)입니까? 내가 본 적이 있다면 그것은 코드 냄새입니다. SQL Server가 이러한 열을 저장하는 방법을 알고 있습니까? 8k 페이지에 맞지 않기 때문에 실제 행에서 열이 저장되는 위치에 대한 포인터를 사용합니다.


비 유니 코드 문자열 데이터 유형 :
텍스트 파일에는 STR을 사용하고 SQL Server 열에는 VARCHAR을 사용합니다.

유니 코드 문자열 데이터 형식 :
텍스트 파일에는 W_STR을 사용하고 SQL Server 열에는 NVARCHAR을 사용합니다.

문제는 데이터 유형이 일치하지 않아 변환 중에 데이터가 손실 될 수 있다는 것입니다.


두 가지 솔루션 : 1- 대상 열의 유형이 [nvarchar] 인 경우 [varchar]로 변경해야합니다.

2- "파생 열"구성 요소를 SSIS 패키지에 추가하고 다음 식을 사용하여 새 열을 추가합니다.
(DT_WSTR,«length») [ColumnName]

Length는 대상 테이블의 열 길이이고 ColumnName은 대상 테이블의 열 이름입니다. 마지막으로 매핑 부분에서 원래 열 대신 새로 추가 된 열을 사용해야합니다.


이것이 SSIS의 모범 사례인지 확실하지 않지만 때때로 이러한 유형의 활동을 수행하려고 할 때 도구가 약간 어색하다는 것을 알게됩니다.

구성 요소를 사용하는 대신 쿼리 내에서 데이터를 변환 할 수 있습니다.

하는 대신

SELECT myField = myNvarchar20Field
FROM myTable

당신은 할 수 있습니다

SELECT myField = CONVERT(VARCHAR(20),myNvarchar20Field)
FROM myTable

이것은 IDE를 사용하여 수정하는 솔루션입니다.

  1. Data Conversion아래와 같이 데이터 흐름에 항목을 추가 합니다.

여기에 이미지 설명 입력

  1. Data Conversion항목을 두 번 클릭 하고 다음과 같이 설정합니다.

여기에 이미지 설명 입력

  1. 이제 DB Destination항목을 두 번 클릭하고을 클릭하고 입력 열 이 실제로 출력이 아닌 [열 이름]의 사본에서 오는 것과 동일한 지 Mapping확인합니다 (여기에서주의하십시오). 다음은 스크린 샷입니다.Data ConversionDB Source

여기에 이미지 설명 입력

그게 다야 .. 저장하고 실행 ..


Mike, I had the same problem with SSIS in SQL Server 2005... Apparently, the DataFlowDestination object will always attempt to validate the data coming in, into Unicode. Go to that object, Advanced Editor, Component Properties pane, change the "ValidateExternalMetaData" property to False. Now, go to the Input and Output Properties pane, Destination Input, External Columns - set each column Data type and Length to match the database table it's going to. Now, when you close that editor, those column changes will be saved and not validated over, and it will work.


Follow the below steps to avoid (cannot convert between unicode and non-unicode string data types) this error

i) Add the Data conversion Transformation tool to your DataFlow.
ii) To open the DataFlow Conversion and select [string DT_STR] datatype.
iii) Then go to Destination flow, select Mapping.
iv) change your i/p name to copy of the name.


Get to the registry to configuration of the client and change the LANG. For Oracle, go to HLM\SOFTWARE\ORACLE\KEY_ORACLIENT...HOME\NLS_LANG and change to appropriate language.


The dts data Conversion task is time taking if there are 50 plus columns!Found a fix for this at the below link

http://rdc.codeplex.com/releases/view/48420

However, it does not seem to work for versions above 2008. So this is how i had to work around the problem

*Open the .DTSX file on Notepad++. Choose language as XML
*Goto the <DTS:FlatFileColumns> tag. Select all items within this tag
*Find the string **DTS:DataType="129"**  replace with **DTS:DataType="130"**
*Save the .DTSX file. 
*Open the project again on Visual Studio BIDS
*Double Click on the Source Task . You would get the message

the metadata of the following output columns does not match the metadata of the external columns with which the output columns are associated:
...
Do you want to replace the metadata of the output columns with the metadata of the external columns?

 *Now Click Yes. We are done !

Resolved - to the original ask:

I've seen this before. Easiest way to fix (don't need all those data conversion steps as ALL of the meta data is available from the source connection):

Delete the OLE DB Source & OLE DB Destinations Make sure Delayed Validation is FALSE (you can set it to True later) Recreate the OLE DB Source with your query, etc. Verify in the Advanced Editor that all of the output data column types are correct Recreate your OLE DB Destination, map, create new table (or remap to existing) and you'll see that SSIS got all the data types correct (same as source).

So much easier that the stuff above.


Not sure if this is still a problem but I found this simple solution:

  1. Right-Click Ole DB Source
  2. Select 'Edit'
  3. Select Input and Output Properties Tab
  4. Under "Inputs and Outputs", Expand "Ole DB Source Output" External Columns and Output Columns
  5. In Output columns, select offending field, on the right-hand panel ensure Data Type Property matches that of the field in External Columns properties

Hope this was clear and easy to follow


Sometime we get this error when we select static character as a field in source query/view/procedure and the destination field data type in Unicode.

Below is the issue i faced: I used the script below at source

and got the error message Column "CATEGORY" cannot convert between Unicode and non-Unicode string data types. as below: error message

Resolution: I tried multiple options but none worked for me. Then I prefixed the static value with N to make in Unicode as below:

SELECT N'STUDENT DETAIL' CATEGORY, NAME, DATEOFBIRTH FROM STUDENTS
UNION
SELECT N'FACULTY DETAIL' CATEGORY, NAME, DATEOFBIRTH FROM FACULTY

If anyone is still experiencing this issue, I found that it related to a difference in Oracle Client versions.

I have posted my full experience and solution here: https://stackoverflow.com/a/43806765/923177


1.add a Data Conversion tool from toolbox
2.Open it,It shows all coloumns from excel ,convert it to desire output. take note of the Output Alias of
each applicable column (they are named Copy Of [original column name] by default)
3.now, in the Destination step, click on Mappings

I changed ValidateExternalMetadata=False for each transformation task. It worked for me.

참고 URL : https://stackoverflow.com/questions/1299575/import-package-error-cannot-convert-between-unicode-and-non-unicode-string-dat

반응형