Gestire l’errore Truncation nell’importazione da Excel a SQL Server 2005

sql server

Spesso importando dati da un file Excel capita di ricevere da SQL SERVER 2005 il seguente errore :

Error 0xc020901c: Data Flow Task: There was an error with output column “Nome Campo” (63) on output “Excel Source Output” (9). The column status returned was: “Text was truncated or one or more characters had no match in the target code page.”

Il Jet Driver di default controlla solo le prime 8 colonne per indovinare la misura massima delle righe. Così se le tue prime 8 colonne sono più piccole di 255 caratteri e la colonna 9 ha più caratteri SQL Server restituisce l’errore sopra riportato.

La soluzione è andare nel Registro di Configurazione di Windows e seguire le istruzioni di Microsoft:

To change the value of TypeGuessRows, use these steps:

  1. On the menu, click . In the dialog box, type , and then click .StartRunRunRegedt32OK
  2. Open the following key in the Registry editor:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel

    Note For 64-bit systems, the corresponding key is as follows:

    HKLM\SOFTWARE\wow6432node\microsoft\jet\4.0\engines\excel
  3. Double-click TypeGuessRows.
  4. In the DWORD editor dialog box, click Decimal under Base. Type a value between 0 and 16, inclusive, for Value data.
  5. Click OK, and then exit the Registry Editor.

A second way to work around this problem (without modifying the registry) is to make sure that rows with fields, which have data 255 characters or greater, are present in the first 8 rows of the source data file.

L’intervallo valido di valori per la chiave TypeGuessRows va da 0 a 16. Tuttavia, se il valore è 0, il numero di righe di origine analizzati è 16384. Tenete a mente che un valore pari a zero potrebbe causare una prestazione piccola colpito se il file sorgente è molto grande.

La modifica funziona benissimo. Fatemi sapere se avete avuto problemi.

Ciao


Se volete seguire i post di www.informarea.it potete iscrivervi al suo feed RSS.


Fabrizio Cannatelli

Autore e Founder di Informarea, sono un appassionato di informatica e tecnologia da sempre. La voglia di comunicare e di condividere sul Web le mie curiosità e le mie conoscenze, mi ha spinto a lanciarmi nel progetto di questo sito. Nato un po' per gioco e un po' per passione, oggi è diventato una grande realtà.

Fabrizio Cannatelli

Approfondimenti